🚸 Remember current values as default in create user stepper

This commit is contained in:
Manuel
2023-08-05 15:09:48 +02:00
parent d081ccb9ad
commit 5b1b36eecc
4 changed files with 22 additions and 7 deletions

View File

@@ -5,13 +5,15 @@ import { z } from 'zod';
interface CreateAccountStepProps { interface CreateAccountStepProps {
nextStep: ({ eMail, username }: { username: string; eMail: string }) => void; nextStep: ({ eMail, username }: { username: string; eMail: string }) => void;
defaultUsername: string;
defaultEmail: string;
} }
export const CreateAccountStep = ({ nextStep }: CreateAccountStepProps) => { export const CreateAccountStep = ({ defaultEmail, defaultUsername, nextStep }: CreateAccountStepProps) => {
const form = useForm({ const form = useForm({
initialValues: { initialValues: {
username: '', username: defaultUsername,
eMail: '', eMail: defaultEmail,
}, },
validateInputOnBlur: true, validateInputOnBlur: true,
validateInputOnChange: true, validateInputOnChange: true,

View File

@@ -43,17 +43,19 @@ function getStrength(password: string) {
} }
interface CreateAccountSecurityStepProps { interface CreateAccountSecurityStepProps {
defaultPassword: string;
nextStep: ({ password }: { password: string }) => void; nextStep: ({ password }: { password: string }) => void;
prevStep: () => void; prevStep: () => void;
} }
export const CreateAccountSecurityStep = ({ export const CreateAccountSecurityStep = ({
defaultPassword,
nextStep, nextStep,
prevStep, prevStep,
}: CreateAccountSecurityStepProps) => { }: CreateAccountSecurityStepProps) => {
const form = useForm({ const form = useForm({
initialValues: { initialValues: {
password: '', password: defaultPassword,
}, },
validateInputOnBlur: true, validateInputOnBlur: true,
validateInputOnChange: true, validateInputOnChange: true,

View File

@@ -8,7 +8,7 @@ import {
IconLogout, IconLogout,
IconMoonStars, IconMoonStars,
IconSun, IconSun,
IconUserCog IconUserCog,
} from '@tabler/icons-react'; } from '@tabler/icons-react';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { User } from 'next-auth'; import { User } from 'next-auth';

View File

@@ -73,6 +73,8 @@ const CreateNewUserPage = () => {
description="Create account" description="Create account"
> >
<CreateAccountStep <CreateAccountStep
defaultUsername={form.values.account.username}
defaultEmail={form.values.account.eMail}
nextStep={(value) => { nextStep={(value) => {
form.setFieldValue('account', value); form.setFieldValue('account', value);
nextStep(); nextStep();
@@ -87,6 +89,7 @@ const CreateNewUserPage = () => {
description="Password" description="Password"
> >
<CreateAccountSecurityStep <CreateAccountSecurityStep
defaultPassword={form.values.security.password}
nextStep={(value) => { nextStep={(value) => {
form.setFieldValue('security', value); form.setFieldValue('security', value);
nextStep(); nextStep();
@@ -160,7 +163,15 @@ const CreateNewUserPage = () => {
</tbody> </tbody>
</Table> </Table>
<Flex justify="end" wrap="nowrap"> <Group position="apart" noWrap>
<Button
leftIcon={<IconArrowLeft size="1rem" />}
onClick={prevStep}
variant="light"
px="xl"
>
Previous
</Button>
<Button <Button
onClick={async () => { onClick={async () => {
await mutateAsync({ await mutateAsync({
@@ -176,7 +187,7 @@ const CreateNewUserPage = () => {
> >
Confirm Confirm
</Button> </Button>
</Flex> </Group>
</Card> </Card>
</Stepper.Step> </Stepper.Step>
<Stepper.Completed> <Stepper.Completed>