-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Moved Entities folder to match the server structure
- Loading branch information
1 parent
760d314
commit 9b11b4b
Showing
17 changed files
with
1,067 additions
and
1,063 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
202 changes: 101 additions & 101 deletions
202
src/Chrono/ClientApp/src/Features/MasterData/MasterDataItemEditModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,118 @@ | ||
import {useEffect, useState} from "react"; | ||
import {MasterDataItem} from "./MasterDataItem"; | ||
import {Button, Checkbox, Form, Input, Modal} from "semantic-ui-react"; | ||
import {UserSettings} from "../../Entities/User"; | ||
import {TaskListOptions} from "../../Entities/TaskListOptions"; | ||
|
||
// Shared | ||
import JSendApiClient, {API_ENDPOINTS} from "../../Shared/JSendApiClient.ts"; | ||
import {UserSettings} from "../../Shared/Entities/User.ts"; | ||
import {TaskListOptions} from "../../Shared/Entities/TaskListOptions.ts"; | ||
import JSendApiClient, {API_ENDPOINTS} from "../../Shared/JSendApiClient"; | ||
|
||
/** Does only support TaskList MasterDataItems at the moment. */ | ||
const MasterDataItemEditModal = (props: { | ||
context?: MasterDataItem, | ||
onButtonClick?: (saved: boolean) => void; | ||
context?: MasterDataItem, | ||
onButtonClick?: (saved: boolean) => void; | ||
}) => { | ||
const [title, setTitle] = useState(props.context?.name); | ||
const [requireDescription, setRequireDescription] = useState(true); | ||
const [requireBusinessValue, setRequireBusinessValue] = useState(true); | ||
const [dataLoaded, setDataLoaded] = useState(false); | ||
const [isDefaultList, setDefaultList] = useState(true); | ||
const [title, setTitle] = useState(props.context?.name); | ||
const [requireDescription, setRequireDescription] = useState(true); | ||
const [requireBusinessValue, setRequireBusinessValue] = useState(true); | ||
const [dataLoaded, setDataLoaded] = useState(false); | ||
const [isDefaultList, setDefaultList] = useState(true); | ||
|
||
useEffect(() => { | ||
const dataFetch = async () => { | ||
useEffect(() => { | ||
const dataFetch = async () => { | ||
|
||
if (props.context) { | ||
const userSettings = await JSendApiClient.get<UserSettings>(API_ENDPOINTS.UserSettings); | ||
setDefaultList(props.context.id === userSettings?.defaultTaskListId); | ||
} | ||
if (props.context) { | ||
const userSettings = await JSendApiClient.get<UserSettings>(API_ENDPOINTS.UserSettings); | ||
setDefaultList(props.context.id === userSettings?.defaultTaskListId); | ||
} | ||
|
||
const options = props.context ? | ||
await JSendApiClient.get<TaskListOptions>(`${API_ENDPOINTS.TaskLists}/${props.context.id}/options`) : | ||
null; | ||
const options = props.context ? | ||
await JSendApiClient.get<TaskListOptions>(`${API_ENDPOINTS.TaskLists}/${props.context.id}/options`) : | ||
null; | ||
|
||
if (options) { | ||
setRequireBusinessValue(options.requireBusinessValue); | ||
setRequireDescription(options.requireDescription); | ||
} | ||
setDataLoaded(true); | ||
}; | ||
dataFetch(); | ||
}, [props]); | ||
if (options) { | ||
setRequireBusinessValue(options.requireBusinessValue); | ||
setRequireDescription(options.requireDescription); | ||
} | ||
setDataLoaded(true); | ||
}; | ||
dataFetch(); | ||
}, [props]); | ||
|
||
return ( | ||
<Modal open={dataLoaded}> | ||
<Modal.Header>Edit {title || 'item'}</Modal.Header> | ||
<Modal.Content> | ||
<Modal.Description> | ||
<Form> | ||
<Form.Field | ||
autoFocus | ||
control={Input} | ||
label="Name" | ||
placeholder="Name" | ||
value={title} | ||
onChange={(e: any) => { | ||
setTitle(e.target.value); | ||
}} | ||
required | ||
></Form.Field> | ||
<Form.Field | ||
control={Checkbox} | ||
label="Require Business Value" | ||
checked={requireBusinessValue} | ||
onClick={() => { | ||
setRequireBusinessValue(!requireBusinessValue); | ||
}} | ||
/> | ||
<Form.Field | ||
control={Checkbox} | ||
label="Require Description" | ||
checked={requireDescription} | ||
onClick={() => { | ||
setRequireDescription(!requireDescription); | ||
}} | ||
/> | ||
</Form> | ||
</Modal.Description> | ||
</Modal.Content> | ||
<Modal.Actions> | ||
{<Button | ||
color="green" | ||
onClick={() => { | ||
const defaultTaskListId = isDefaultList ? undefined : props.context!.id; | ||
JSendApiClient.update(API_ENDPOINTS.UserSettings, {defaultTaskListId}) | ||
.then(isDone => { | ||
if (isDone) | ||
props.onButtonClick!(true); | ||
}); | ||
}} | ||
> | ||
{isDefaultList ? "Unset default" : "Set as default"} | ||
</Button>} | ||
<Button | ||
onClick={() => props.onButtonClick!(false)} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
primary | ||
content="Save" | ||
onClick={() => { | ||
JSendApiClient.update(`${API_ENDPOINTS.TaskLists}/${props.context!.id}`, { | ||
taskListId: props.context!.id, | ||
title: title || 'Item', | ||
requireBusinessValue: requireBusinessValue, | ||
requireDescription: requireDescription | ||
}).then((isDone) => { | ||
if (isDone) { | ||
props.onButtonClick!(true); | ||
} | ||
}); | ||
}} | ||
/> | ||
</Modal.Actions> | ||
</Modal> | ||
); | ||
return ( | ||
<Modal open={dataLoaded}> | ||
<Modal.Header>Edit {title || 'item'}</Modal.Header> | ||
<Modal.Content> | ||
<Modal.Description> | ||
<Form> | ||
<Form.Field | ||
autoFocus | ||
control={Input} | ||
label="Name" | ||
placeholder="Name" | ||
value={title} | ||
onChange={(e: any) => { | ||
setTitle(e.target.value); | ||
}} | ||
required | ||
></Form.Field> | ||
<Form.Field | ||
control={Checkbox} | ||
label="Require Business Value" | ||
checked={requireBusinessValue} | ||
onClick={() => { | ||
setRequireBusinessValue(!requireBusinessValue); | ||
}} | ||
/> | ||
<Form.Field | ||
control={Checkbox} | ||
label="Require Description" | ||
checked={requireDescription} | ||
onClick={() => { | ||
setRequireDescription(!requireDescription); | ||
}} | ||
/> | ||
</Form> | ||
</Modal.Description> | ||
</Modal.Content> | ||
<Modal.Actions> | ||
{<Button | ||
color="green" | ||
onClick={() => { | ||
const defaultTaskListId = isDefaultList ? undefined : props.context!.id; | ||
JSendApiClient.update(API_ENDPOINTS.UserSettings, {defaultTaskListId}) | ||
.then(isDone => { | ||
if (isDone) | ||
props.onButtonClick!(true); | ||
}); | ||
}} | ||
> | ||
{isDefaultList ? "Unset default" : "Set as default"} | ||
</Button>} | ||
<Button | ||
onClick={() => props.onButtonClick!(false)} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
primary | ||
content="Save" | ||
onClick={() => { | ||
JSendApiClient.update(`${API_ENDPOINTS.TaskLists}/${props.context!.id}`, { | ||
taskListId: props.context!.id, | ||
title: title || 'Item', | ||
requireBusinessValue: requireBusinessValue, | ||
requireDescription: requireDescription | ||
}).then((isDone) => { | ||
if (isDone) { | ||
props.onButtonClick!(true); | ||
} | ||
}); | ||
}} | ||
/> | ||
</Modal.Actions> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default MasterDataItemEditModal; |
Oops, something went wrong.