-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a4f051
commit 8b6885b
Showing
18 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-986 KB
.yarn/cache/@rollup-rollup-linux-x64-gnu-npm-4.24.0-a67121f2c9-10.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+16.1 MB
...inux-x64-gnu-npm-1.7.36-24fed95b50-10.zip → ...darwin-arm64-npm-1.7.36-9c1682cc14-10.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/rc-service/src/components/users/update-user-name.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { FC } from 'react' | ||
import { Button, FormLayout, InputGroup, InputWrapFull, Modal, Title, useModal } from '@reapit/elements' | ||
import { UpdateActionNames, updateActions, useReapitUpdate } from '@reapit/use-reapit-data' | ||
import { reapitConnectBrowserSession } from '../../core/connect-session' | ||
import { UserModel } from '@reapit/foundations-ts-definitions' | ||
import { useForm } from 'react-hook-form' | ||
import { yupResolver } from '@hookform/resolvers/yup' | ||
import { object, string } from 'yup' | ||
|
||
const validationSchema = object().shape({ | ||
name: string().trim().required('Required').max(150, 'Limit of 150 characters'), | ||
}) | ||
|
||
export const UpdateUserName: FC<{ user: UserModel }> = ({ user }) => { | ||
const { modalIsOpen, openModal, closeModal } = useModal() | ||
|
||
const [isLoading, , updateUser] = useReapitUpdate<UserModel, UserModel>({ | ||
uriParams: { | ||
userId: user.id, | ||
}, | ||
action: updateActions[UpdateActionNames.updateUser], | ||
reapitConnectBrowserSession, | ||
method: 'PATCH', | ||
}) | ||
|
||
const { | ||
register, | ||
handleSubmit, | ||
formState: { errors: formErrors }, | ||
} = useForm<{ name?: string }>({ | ||
resolver: yupResolver(validationSchema) as any, | ||
defaultValues: { | ||
name: user.name, | ||
}, | ||
}) | ||
|
||
return ( | ||
<> | ||
<Button intent="primary" onClick={() => openModal()}> | ||
Update User's Name | ||
</Button> | ||
<Modal | ||
isOpen={modalIsOpen} | ||
onModalClose={() => { | ||
closeModal() | ||
}} | ||
> | ||
<form | ||
onSubmit={handleSubmit(({ name }) => { | ||
console.log('update name', name) | ||
|
||
updateUser({ | ||
name, | ||
}) | ||
})} | ||
> | ||
<FormLayout> | ||
<InputWrapFull> | ||
<Title>Update Name</Title> | ||
</InputWrapFull> | ||
<InputWrapFull> | ||
<InputGroup | ||
label="Name" | ||
{...register('name')} | ||
errorMessage={formErrors?.name?.message} | ||
icon={formErrors?.name?.message ? 'asterisk' : null} | ||
/> | ||
</InputWrapFull> | ||
<InputWrapFull> | ||
<Button loading={isLoading} disabled={isLoading} intent="primary"> | ||
Update | ||
</Button> | ||
</InputWrapFull> | ||
</FormLayout> | ||
</form> | ||
</Modal> | ||
</> | ||
) | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters