Skip to content

Commit

Permalink
refactor: Moved Entities folder to match the server structure
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-meier committed Nov 11, 2023
1 parent 760d314 commit 9b11b4b
Show file tree
Hide file tree
Showing 17 changed files with 1,067 additions and 1,063 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
202 changes: 101 additions & 101 deletions src/Chrono/ClientApp/src/Features/MasterData/MasterDataItemEditModal.tsx
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;
Loading

0 comments on commit 9b11b4b

Please sign in to comment.