Files
Homarr/src/components/Manage/User/Create/review-input-step.tsx

121 lines
3.5 KiB
TypeScript
Raw Normal View History

2023-08-22 21:52:14 +02:00
import { Alert, Button, Card, Group, Table, Text, Title } from '@mantine/core';
2023-08-06 14:12:39 +02:00
import {
2023-08-22 21:52:14 +02:00
IconAlertTriangle,
IconAlertTriangleFilled,
2023-08-06 14:12:39 +02:00
IconArrowLeft,
IconCheck,
IconInfoCircle,
IconKey,
IconMail,
IconUser,
} from '@tabler/icons-react';
import { useTranslation } from 'next-i18next';
import { CreateAccountSchema } from '~/pages/manage/users/create';
import { api } from '~/utils/api';
type ReviewInputStepProps = {
values: CreateAccountSchema;
prevStep: () => void;
nextStep: () => void;
};
export const ReviewInputStep = ({ values, prevStep, nextStep }: ReviewInputStepProps) => {
const { t } = useTranslation('manage/users/create');
const utils = api.useContext();
2023-08-22 21:52:14 +02:00
const { mutateAsync: createAsync, isLoading, isError, error } = api.user.create.useMutation({
2023-08-06 14:12:39 +02:00
onSettled: () => {
void utils.user.all.invalidate();
},
onSuccess: () => {
nextStep();
},
});
return (
<Card mih={400}>
<Title order={5}>{t('steps.finish.card.title')}</Title>
<Text mb="xl">{t('steps.finish.card.text')}</Text>
<Table mb="lg" withBorder highlightOnHover>
<thead>
<tr>
<th>{t('steps.finish.table.header.property')}</th>
<th>{t('steps.finish.table.header.value')}</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<Group spacing="xs">
<IconUser size="1rem" />
<Text>{t('steps.finish.table.header.username')}</Text>
</Group>
</td>
<td>{values.account.username}</td>
</tr>
<tr>
<td>
<Group spacing="xs">
<IconMail size="1rem" />
<Text>{t('steps.finish.table.header.email')}</Text>
</Group>
</td>
<td>
{values.account.eMail ? (
<Text>{values.account.eMail}</Text>
) : (
<Group spacing="xs">
<IconInfoCircle size="1rem" color="orange" />
<Text color="orange">{t('steps.finish.table.notSet')}</Text>
</Group>
)}
</td>
</tr>
<tr>
<td>
<Group spacing="xs">
<IconKey size="1rem" />
<Text>{t('steps.finish.table.header.password')}</Text>
2023-08-06 14:12:39 +02:00
</Group>
</td>
<td>
<Group spacing="xs">
<IconCheck size="1rem" color="green" />
<Text color="green">{t('steps.finish.table.valid')}</Text>
</Group>
</td>
</tr>
</tbody>
</Table>
2023-08-22 21:52:14 +02:00
{isError && (
<Alert color="red" icon={<IconAlertTriangleFilled size="0.9rem" />} mb="lg">
2023-08-22 21:55:26 +02:00
<Text color="red">{t('steps.finish.failed', { error: error.message })}</Text>
2023-08-22 21:52:14 +02:00
</Alert>
)}
2023-08-06 14:12:39 +02:00
<Group position="apart" noWrap>
<Button leftIcon={<IconArrowLeft size="1rem" />} onClick={prevStep} variant="light" px="xl">
{t('common:previous')}
2023-08-06 14:12:39 +02:00
</Button>
<Button
onClick={async () => {
await createAsync({
username: values.account.username,
password: values.security.password,
email: values.account.eMail === '' ? undefined : values.account.eMail,
});
}}
loading={isLoading}
rightIcon={<IconCheck size="1rem" />}
variant="light"
px="xl"
>
{t('common:confirm')}
2023-08-06 14:12:39 +02:00
</Button>
</Group>
</Card>
);
};