Skip to content

Commit

Permalink
🐛 fix: reset stored user info upon successful sign-up (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
rezk2ll committed Jun 10, 2024
1 parent e770b60 commit 04ac357
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import PrimaryButton from '$components/buttons/PrimaryButton.svelte';
import PasswordField from '$components/input/PasswordField.svelte';
import { createUserFormSchema, fullCreateUserFormSchema } from '$lib/schemas/zodSchema';
import { resetUserInfo } from '$src/store';
import { t } from 'svelte-i18n';
let sendPasswordForm: HTMLFormElement;
Expand All @@ -11,10 +12,11 @@
let confirmPassword = '';
let loading = false;
$: disabled = !fullCreateUserFormSchema.safeParse({
password,
confirmPassword
}).success || loading;
$: disabled =
!fullCreateUserFormSchema.safeParse({
password,
confirmPassword
}).success || loading;
const handler = () => {
if (disabled) return;
Expand All @@ -35,6 +37,7 @@
loading = false;

update();
resetUserInfo();
};
}}
>
Expand Down
19 changes: 14 additions & 5 deletions registration/src/store/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import type { UserInfo, RegistrationStepType } from '$types';
import { writable, get } from 'svelte/store';
import type { ActionData } from '../routes/$types';

const defaultUserInfo = {
firstName: '',
lastName: '',
nickName: ''
};

export const form = writable<ActionData>();
export const registrationStep = writable<RegistrationStepType>('home');

Expand Down Expand Up @@ -35,8 +41,11 @@ export const nextRegistrationStep = () => {
if (currentStep === 'password') return registrationStep.set('success');
};

export const nickNameStepInfo = writable<UserInfo>({
firstName: '',
lastName: '',
nickName: ''
});
export const nickNameStepInfo = writable<UserInfo>(defaultUserInfo);

/**
* Resets the default user info Store
*/
export const resetUserInfo = (): void => {
nickNameStepInfo.set(defaultUserInfo);
};

0 comments on commit 04ac357

Please sign in to comment.