Skip to content

Commit

Permalink
feat: add validation for add user
Browse files Browse the repository at this point in the history
  • Loading branch information
mois-ilya committed Jul 23, 2024
1 parent b5e6c95 commit 2c9e99d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/entities/project/ui/AddProjectParticipanModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ const AddProjectParticipanModal: FC<{
.catch(() => console.error('Error'));
};

// TODO reset form after close
// useEffect(() => {
// return () => reset();
// });

const { ref: maskRef } = useIMask({
// FIXME: useIMask is not work
mask: Number,
scale: 0,
signed: false,
Expand All @@ -46,12 +52,20 @@ const AddProjectParticipanModal: FC<{
});

const { ref: hookFormRef, ...amountRest } = register('userId', {
required: 'This is required', // TODO add validation for existing user
required: 'This is required',
validate: value => {
if (
projectsStore.projectParticipants$.value.find(
participant => participant.id === value
)
) {
return 'User already exists';
}
return true;
},
valueAsNumber: true
});

// TODO reset form after close

return (
<Modal scrollBehavior="inside" {...rest}>
<ModalOverlay />
Expand Down

0 comments on commit 2c9e99d

Please sign in to comment.