-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fab changes * progress bar * remove unused page components * focus * remove onCancel from user form * remove onCancel globally * tests * fixes
- Loading branch information
Showing
15 changed files
with
237 additions
and
201 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.fab-user-add { | ||
.ls-fab-user-add { | ||
.icon { | ||
font-size: 1.125rem; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { IonModalCustomEvent } from '@ionic/core'; | ||
import { OverlayEventDetail } from '@ionic/react/dist/types/components/react-component-lib/interfaces'; | ||
import { | ||
IonButton, | ||
IonButtons, | ||
IonContent, | ||
IonHeader, | ||
IonModal, | ||
IonProgressBar, | ||
IonTitle, | ||
IonToolbar, | ||
useIonRouter, | ||
} from '@ionic/react'; | ||
import { ComponentPropsWithoutRef, useState } from 'react'; | ||
|
||
import { PropsWithTestId } from 'common/components/types'; | ||
import { useCreateUser } from 'pages/Users/api/useCreateUser'; | ||
import { useProgress } from 'common/hooks/useProgress'; | ||
import { useToasts } from 'common/hooks/useToasts'; | ||
import { DismissButton } from 'common/components/Toast/Toast'; | ||
import Icon, { IconName } from 'common/components/Icon/Icon'; | ||
import UserForm from '../UserForm/UserForm'; | ||
import ErrorCard from 'common/components/Card/ErrorCard'; | ||
|
||
/** | ||
* Properties for the `UserAddModal` component. | ||
* @param {function} setIsOpen - A setter function which accepts a `boolean` that | ||
* indicates if the modal should be open (`true`) or closed (`false`). | ||
* @see {@link PropsWithTestId} | ||
* @see {@link IonModal} | ||
*/ | ||
interface UserAddModalProps extends PropsWithTestId, ComponentPropsWithoutRef<typeof IonModal> { | ||
setIsOpen: (isOpen: boolean) => void; | ||
} | ||
|
||
/** | ||
* The `UserAddModal` component renders an `IonModal` containing a Formik | ||
* form to create a new `User`. | ||
* | ||
* @param {UserAddModalProps} props - Component properties. | ||
* @returns {JSX.Element} JSX | ||
*/ | ||
const UserAddModal = ({ | ||
onIonModalDidDismiss, | ||
setIsOpen, | ||
testid = 'modal-user-add', | ||
...modalProps | ||
}: UserAddModalProps): JSX.Element => { | ||
const [error, setError] = useState<string>(''); | ||
const router = useIonRouter(); | ||
const { isActive: isActiveProgressBar, progressBar, setProgress } = useProgress(); | ||
const { createToast } = useToasts(); | ||
const { mutate: createUser } = useCreateUser(); | ||
|
||
const didDismiss = (e: IonModalCustomEvent<OverlayEventDetail>) => { | ||
onIonModalDidDismiss?.(e); | ||
setIsOpen(false); | ||
}; | ||
|
||
return ( | ||
<IonModal onIonModalDidDismiss={didDismiss} {...modalProps} data-testid={testid}> | ||
<IonHeader> | ||
<IonToolbar> | ||
<IonTitle>Add User</IonTitle> | ||
|
||
<IonButtons slot="end"> | ||
<IonButton onClick={() => setIsOpen(false)} data-testid={`${testid}-button-close`}> | ||
<Icon icon={IconName.Xmark} /> | ||
</IonButton> | ||
</IonButtons> | ||
|
||
{isActiveProgressBar && <IonProgressBar className="ion-hide-md-up" {...progressBar} />} | ||
</IonToolbar> | ||
</IonHeader> | ||
<IonContent class="ion-padding"> | ||
{error && ( | ||
<ErrorCard | ||
content={`We are experiencing problems processing your request. ${error}`} | ||
className="ion-margin-bottom" | ||
testid={`${testid}-error`} | ||
/> | ||
)} | ||
<UserForm | ||
onSubmit={(values, { setSubmitting }) => { | ||
setProgress(true); | ||
setError(''); | ||
createUser( | ||
{ user: values }, | ||
{ | ||
onSuccess: (user) => { | ||
setProgress(false); | ||
setSubmitting(false); | ||
createToast({ | ||
buttons: [DismissButton], | ||
duration: 5000, | ||
message: `${user.name} created`, | ||
}); | ||
setIsOpen(false); | ||
router.push(`/tabs/users/${user.id}`); | ||
}, | ||
onError(error) { | ||
setProgress(false); | ||
setError(error.message); | ||
setSubmitting(false); | ||
}, | ||
}, | ||
); | ||
}} | ||
testid={`${testid}-form`} | ||
/> | ||
</IonContent> | ||
</IonModal> | ||
); | ||
}; | ||
|
||
export default UserAddModal; |
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/pages/Users/components/UserAdd/__tests__/UserAdd.test.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.