🚸 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 {
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({
initialValues: {
username: '',
eMail: '',
username: defaultUsername,
eMail: defaultEmail,
},
validateInputOnBlur: true,
validateInputOnChange: true,

View File

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

View File

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

View File

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