| @@ -26,8 +26,13 @@ export interface NewTaskTemplateFormInputs { | |||||
| }; | }; | ||||
| } | } | ||||
| export interface NewTaskTemplateResponse { | |||||
| taskTemplate: TaskTemplate; | |||||
| message: string; | |||||
| } | |||||
| export const saveTaskTemplate = async (data: NewTaskTemplateFormInputs) => { | export const saveTaskTemplate = async (data: NewTaskTemplateFormInputs) => { | ||||
| const newTaskTemplate = await serverFetchJson<TaskTemplate>( | |||||
| const newTaskTemplate = await serverFetchJson<NewTaskTemplateResponse>( | |||||
| `${BASE_API_URL}/tasks/templates/save`, | `${BASE_API_URL}/tasks/templates/save`, | ||||
| { | { | ||||
| method: "POST", | method: "POST", | ||||
| @@ -48,9 +48,13 @@ const Milestone: React.FC<Props> = ({ allTasks, isActive }) => { | |||||
| ); | ); | ||||
| const [currentTaskGroupId, setCurrentTaskGroupId] = useState( | const [currentTaskGroupId, setCurrentTaskGroupId] = useState( | ||||
| taskGroups[0].id, | |||||
| taskGroups[0].id | |||||
| ); | ); | ||||
| useEffect(() => { | |||||
| if (taskGroups.length >= 0 && !taskGroups.map(taskGroup => taskGroup.id).includes(currentTaskGroupId)) setCurrentTaskGroupId(taskGroups[0].id) | |||||
| }, [taskGroups]) | |||||
| /*const onSelectTaskGroup = useCallback( | /*const onSelectTaskGroup = useCallback( | ||||
| (event: SelectChangeEvent<TaskGroup["id"]>) => { | (event: SelectChangeEvent<TaskGroup["id"]>) => { | ||||
| const id = event.target.value; | const id = event.target.value; | ||||
| @@ -111,7 +115,7 @@ const Milestone: React.FC<Props> = ({ allTasks, isActive }) => { | |||||
| value={taskGroups.find(taskGroup => taskGroup.id === currentTaskGroupId)} | value={taskGroups.find(taskGroup => taskGroup.id === currentTaskGroupId)} | ||||
| options={taskGroups} | options={taskGroups} | ||||
| getOptionLabel={(taskGroup) => taskGroup.name} | getOptionLabel={(taskGroup) => taskGroup.name} | ||||
| isOptionEqualToValue={(option, value) => option.id === value.id} | |||||
| isOptionEqualToValue={(option, value) => option.id === value?.id} | |||||
| renderOption={(params, option) => { | renderOption={(params, option) => { | ||||
| return ( | return ( | ||||
| <MenuItem {...params} key={option.id} value={option.id}> | <MenuItem {...params} key={option.id} value={option.id}> | ||||
| @@ -83,8 +83,6 @@ const CreateTaskTemplate: React.FC<Props> = ({ tasks, defaultInputs, grades }) = | |||||
| const onSubmit: SubmitHandler<NewTaskTemplateFormInputs> = React.useCallback( | const onSubmit: SubmitHandler<NewTaskTemplateFormInputs> = React.useCallback( | ||||
| async (data) => { | async (data) => { | ||||
| try { | try { | ||||
| console.log(data) | |||||
| setServerError(""); | setServerError(""); | ||||
| let hasErrors = false | let hasErrors = false | ||||
| @@ -98,16 +96,17 @@ const CreateTaskTemplate: React.FC<Props> = ({ tasks, defaultInputs, grades }) = | |||||
| } | } | ||||
| if (hasErrors) return false | if (hasErrors) return false | ||||
| submitDialog(async () => { | submitDialog(async () => { | ||||
| const response = await saveTaskTemplate(data); | const response = await saveTaskTemplate(data); | ||||
| if (response?.id !== null && response?.id !== undefined && response?.id > 0) { | |||||
| if (response.message === "Success") { | |||||
| successDialog(t("Submit Success"), t).then(() => { | successDialog(t("Submit Success"), t).then(() => { | ||||
| router.replace("/tasks"); | router.replace("/tasks"); | ||||
| }) | }) | ||||
| } else { | } else { | ||||
| errorDialog(t("Submit Fail"), t).then(() => { | errorDialog(t("Submit Fail"), t).then(() => { | ||||
| formProps.setError("code", { message: response.message, type: "custom" }) | |||||
| return false | return false | ||||
| }) | }) | ||||
| } | } | ||||
| @@ -140,8 +139,8 @@ const CreateTaskTemplate: React.FC<Props> = ({ tasks, defaultInputs, grades }) = | |||||
| {...formProps.register("code", { | {...formProps.register("code", { | ||||
| required: t("Task template code is required"), | required: t("Task template code is required"), | ||||
| })} | })} | ||||
| error={Boolean(formProps.formState.errors.code?.message)} | |||||
| helperText={formProps.formState.errors.code?.message} | |||||
| error={Boolean(formProps.formState.errors.code)} | |||||
| helperText={Boolean(formProps.formState.errors.code) && t(formProps.formState.errors.code?.message!!)} | |||||
| /> | /> | ||||
| </Grid> | </Grid> | ||||
| <Grid item xs={6}> | <Grid item xs={6}> | ||||
| @@ -151,8 +150,8 @@ const CreateTaskTemplate: React.FC<Props> = ({ tasks, defaultInputs, grades }) = | |||||
| {...formProps.register("name", { | {...formProps.register("name", { | ||||
| required: t("Task template name is required"), | required: t("Task template name is required"), | ||||
| })} | })} | ||||
| error={Boolean(formProps.formState.errors.name?.message)} | |||||
| helperText={formProps.formState.errors.name?.message} | |||||
| error={Boolean(formProps.formState.errors.name)} | |||||
| helperText={Boolean(formProps.formState.errors.name) && t(formProps.formState.errors.name?.message!!)} | |||||
| /> | /> | ||||
| </Grid> | </Grid> | ||||
| </Grid> | </Grid> | ||||
| @@ -38,7 +38,7 @@ const CustomerSearch: React.FC<Props> = ({ customers }) => { | |||||
| const onTaskClick = useCallback((customer: Customer) => { | const onTaskClick = useCallback((customer: Customer) => { | ||||
| const params = new URLSearchParams(searchParams.toString()) | const params = new URLSearchParams(searchParams.toString()) | ||||
| params.set("id", customer.id.toString()) | params.set("id", customer.id.toString()) | ||||
| router.replace(`/settings/customer/edit?${params.toString()}`); | |||||
| router.push(`/settings/customer/edit?${params.toString()}`); | |||||
| }, []); | }, []); | ||||
| const onDeleteClick = useCallback((customer: Customer) => { | const onDeleteClick = useCallback((customer: Customer) => { | ||||
| @@ -38,7 +38,7 @@ const SubsidiarySearch: React.FC<Props> = ({ subsidiaries }) => { | |||||
| const onTaskClick = useCallback((subsidiary: Subsidiary) => { | const onTaskClick = useCallback((subsidiary: Subsidiary) => { | ||||
| const params = new URLSearchParams(searchParams.toString()) | const params = new URLSearchParams(searchParams.toString()) | ||||
| params.set("id", subsidiary.id.toString()) | params.set("id", subsidiary.id.toString()) | ||||
| router.replace(`/settings/subsidiary/edit?${params.toString()}`); | |||||
| router.push(`/settings/subsidiary/edit?${params.toString()}`); | |||||
| }, []); | }, []); | ||||
| const onDeleteClick = useCallback((subsidiary: Subsidiary) => { | const onDeleteClick = useCallback((subsidiary: Subsidiary) => { | ||||
| @@ -11,6 +11,7 @@ | |||||
| "Task template code is required": "Task template code is required", | "Task template code is required": "Task template code is required", | ||||
| "Task template name is required": "Task template name is required", | "Task template name is required": "Task template name is required", | ||||
| "The task template code has already existed": "The task template code has already existed", | |||||
| "Do you want to submit?": "Do you want to submit?", | "Do you want to submit?": "Do you want to submit?", | ||||
| "Submit Success": "Submit Success", | "Submit Success": "Submit Success", | ||||
| @@ -11,6 +11,7 @@ | |||||
| "Task template code is required": "需要工作範本編號", | "Task template code is required": "需要工作範本編號", | ||||
| "Task template name is required": "需要工作範本名稱", | "Task template name is required": "需要工作範本名稱", | ||||
| "The task template code has already existed": "該工作範本編號已存在", | |||||
| "Do you want to submit?": "你是否確認要提交?", | "Do you want to submit?": "你是否確認要提交?", | ||||
| "Submit Success": "提交成功", | "Submit Success": "提交成功", | ||||