From 4431d72e09e4f851baa091e894afc39fbb81a8aa Mon Sep 17 00:00:00 2001 From: Davor Date: Sun, 17 Jul 2022 20:00:50 +0200 Subject: [PATCH] modify frontend for add multiple users --- src/components/Form/TextArea/index.ts | 1 + src/components/Form/TextArea/textarea.tsx | 43 ++++ src/components/Form/index.ts | 1 + src/components/UserModal/consts.ts | 19 +- src/modules/users/Users.tsx | 19 +- .../MultipleUsersModal/MultipleUsersModal.tsx | 200 +++++++++--------- .../components/MultipleUsersModal/types.ts | 7 +- .../components/MultipleUsersModal/utils.ts | 14 -- src/services/users/hooks/use-users.ts | 6 + src/services/users/redux/actions.ts | 54 ++++- src/services/users/redux/reducers.ts | 1 + src/services/users/transformations.ts | 30 ++- src/services/users/types.ts | 5 + 13 files changed, 265 insertions(+), 135 deletions(-) create mode 100644 src/components/Form/TextArea/index.ts create mode 100644 src/components/Form/TextArea/textarea.tsx delete mode 100644 src/modules/users/components/MultipleUsersModal/utils.ts diff --git a/src/components/Form/TextArea/index.ts b/src/components/Form/TextArea/index.ts new file mode 100644 index 0000000..9f93c0d --- /dev/null +++ b/src/components/Form/TextArea/index.ts @@ -0,0 +1 @@ +export { TextArea } from './textarea'; diff --git a/src/components/Form/TextArea/textarea.tsx b/src/components/Form/TextArea/textarea.tsx new file mode 100644 index 0000000..2dfa188 --- /dev/null +++ b/src/components/Form/TextArea/textarea.tsx @@ -0,0 +1,43 @@ +import React from 'react'; +import { useController } from 'react-hook-form'; + +/* eslint-disable react/react-in-jsx-scope */ +export const TextArea = ({ control, name, label, required, ...props }: TextAreaProps) => { + const { + field, + // fieldState: { invalid, isTouched, isDirty }, + // formState: { touchedFields, dirtyFields }, + } = useController({ + name, + control, + rules: { required }, + defaultValue: '', + }); + + return ( + <> + {label && ( + + )} + - - ); - }; + const { fields } = useFieldArray({ + control, + name: 'appRoles', + }); const handleSave = async () => { - // try { - // if (userId) { - // await handleSubmit((data) => editUserById(data))(); - // } else { - // await handleSubmit((data) => createNewUser(data))(); - // } - // } catch (e: any) { - // // Continue - // } - - onUpload(); + try { + await handleSubmit((data) => createUsers(data))(); + } catch (e: any) { + // Continue + } onClose(); }; @@ -79,46 +34,87 @@ export const MultipleUsersModal = ({ open, onClose, onUpload }: MultipleUsersMod onClose(); }; + const renderUsersCsvDataInput = () => { + return ( +
+