Skip to content

Commit

Permalink
fix(department): cannot save department without parent
Browse files Browse the repository at this point in the history
  • Loading branch information
Anu-Ujin committed Nov 3, 2023
1 parent 0425557 commit dfecc06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Expand Up @@ -24,7 +24,6 @@ export default function DepartmentForm(props: Props) {
const [userIds, setUserIds] = useState(
(object.users || []).map(user => user._id)
);
const [parentId, setParentId] = useState(object.parentId);
const [supervisorId, setSupervisorId] = useState(object.supervisorId);

const generateDoc = values => {
Expand All @@ -36,20 +35,15 @@ export default function DepartmentForm(props: Props) {

return {
userIds,
parentId,
supervisorId,
...finalValues
parentId: finalValues.parentId ? finalValues.parentId : null,
code: finalValues.code,
description: finalValues.description,
title: finalValues.title,
_id: finalValues._id
};
};

const onChangeParent = (value: any) => {
if (value) {
setParentId(value);
} else {
setParentId(null);
}
};

const onSelectUsers = values => {
setUserIds(values);
};
Expand Down Expand Up @@ -116,8 +110,7 @@ export default function DepartmentForm(props: Props) {
{...formProps}
name="parentId"
componentClass="select"
defaultValue={parentId || null}
onChange={onChangeParent}
defaultValue={object.parentId || null}
>
<option value="" />
{generateOptions()}
Expand Down
Expand Up @@ -10,7 +10,7 @@ import { ModalFooter } from '@erxes/ui/src/styles/main';
import Select from 'react-select-plus';
import SelectStructureMembers from '../SelectStructureMembers';
import { __ } from 'modules/common/utils';
import { generateTree } from '../../utils';
import { generateUserOptions } from '@erxes/ui/src/team/containers/SelectDepartments';

type Props = {
renderButton: (props: IButtonMutateProps) => JSX.Element;
Expand Down Expand Up @@ -112,10 +112,7 @@ export default function DepartmentForm(props: Props) {
placeholder={__('Choose department')}
value={departmentId}
onChange={onChangeDepartment}
options={generateTree(departments, '', (node, level) => ({
value: node._id,
label: `${'---'.repeat(level)} ${node.title}`
}))}
options={generateUserOptions(departments)}
/>
</FormGroup>
<FormGroup>
Expand Down

0 comments on commit dfecc06

Please sign in to comment.