added the checkbox in the task settings when creating a task as an object through keys and types to share the task to the team or user automatically when it is created
This commit is contained in:
parent
324ce7807f
commit
bd15f4a15f
1 changed files with 35 additions and 3 deletions
|
|
@ -2,10 +2,12 @@ import {
|
|||
Avatar,
|
||||
Box,
|
||||
Button,
|
||||
Checkbox,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
FormControlLabel,
|
||||
Grid2 as Grid,
|
||||
InputAdornment,
|
||||
MenuItem,
|
||||
|
|
@ -15,9 +17,9 @@ import moment from "moment";
|
|||
import React, { useState } from "react";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useGlobalState, useTaskAPI } from "providers";
|
||||
import { useSnackbar, useUserAPI } from "hooks";
|
||||
import { usePermissionAPI, useSnackbar, useUserAPI } from "hooks";
|
||||
import { useEffect } from "react";
|
||||
import { Task, teamScope, User } from "models";
|
||||
import { Task, teamScope, User, userScope } from "models";
|
||||
import ColourPicker from "common/ColourPicker";
|
||||
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||
|
||||
|
|
@ -46,13 +48,15 @@ export default function TaskSettings(props: Props) {
|
|||
const [worker, setWorker] = useState(user.id());
|
||||
const [colour, setColour] = useState("");
|
||||
const taskAPI = useTaskAPI();
|
||||
const userAPI = useUserAPI();
|
||||
const permissionAPI = usePermissionAPI();
|
||||
const { openSnack } = useSnackbar();
|
||||
const [cost, setCost] = useState("");
|
||||
const [secondaryCost, setSecondaryCost] = useState("");
|
||||
const [seedCost, setSeedCost] = useState("");
|
||||
const [poundPerAcre, setPoundPerAcre] = useState(0);
|
||||
const userAPI = useUserAPI();
|
||||
const [users, setUsers] = useState<User[]>([]);
|
||||
const [shareToCreator, setShareToCreator] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
if (props.task) {
|
||||
|
|
@ -123,6 +127,22 @@ export default function TaskSettings(props: Props) {
|
|||
taskAPI
|
||||
.addTask(taskSettings, as, props.keys, props.types)
|
||||
.then(resp => {
|
||||
console.log(resp)
|
||||
if(shareToCreator && resp.data.task){
|
||||
let parentScope = userScope(user.id())
|
||||
if(as){
|
||||
parentScope = teamScope(as)
|
||||
}
|
||||
|
||||
permissionAPI.shareObjectByKey(
|
||||
{key: resp.data.task, kind: "task"},
|
||||
parentScope.key,
|
||||
parentScope.kind,
|
||||
[pond.Permission.PERMISSION_READ, pond.Permission.PERMISSION_WRITE, pond.Permission.PERMISSION_USERS, pond.Permission.PERMISSION_SHARE],
|
||||
props.keys,
|
||||
props.types
|
||||
)
|
||||
}
|
||||
props.onClose(true);
|
||||
})
|
||||
.catch(err => {
|
||||
|
|
@ -319,6 +339,18 @@ export default function TaskSettings(props: Props) {
|
|||
value={endTime}
|
||||
onChange={e => setEndTime(e.target.value)}
|
||||
/>
|
||||
{props.keys && props.types && !props.task &&
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={shareToCreator}
|
||||
onChange={e => setShareToCreator(e.target.checked)}
|
||||
color="primary"
|
||||
/>
|
||||
}
|
||||
label={"Share task with " + (as ? "team" : "user")}
|
||||
/>
|
||||
}
|
||||
<Box marginTop={3}>
|
||||
Colour
|
||||
<ColourPicker onChange={color => setColour(color)} />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue