feat: reset verify states after completion
This commit is contained in:
@ -2,7 +2,7 @@ import { Button } from "@/components/ui/button";
|
||||
import Avatar from "@/feature/Avatar";
|
||||
import { useAuth } from "@/store/auth";
|
||||
import { useVerify } from "@/store/verify";
|
||||
import type { FC } from "react";
|
||||
import { type FC } from "react";
|
||||
|
||||
const VerifyReviewPage: FC = () => {
|
||||
const profile = useAuth((s) => s.profile);
|
||||
@ -38,7 +38,7 @@ const VerifyReviewPage: FC = () => {
|
||||
disabled={verifying}
|
||||
onClick={finishVerify}
|
||||
>
|
||||
Back Home
|
||||
Finish
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
|
@ -13,28 +13,25 @@ export type VerifyStep = "email" | "avatar" | "review";
|
||||
|
||||
export interface IVerifyState {
|
||||
step: VerifyStep | null | false;
|
||||
|
||||
redirect: string | null;
|
||||
|
||||
loadStep: (profile: UserProfile) => void;
|
||||
|
||||
requesting: boolean;
|
||||
requested: boolean;
|
||||
requestOTP: () => Promise<void>;
|
||||
|
||||
confirming: boolean;
|
||||
confirmOTP: (req: ConfirmEmailRequest) => Promise<void>;
|
||||
|
||||
uploading: boolean;
|
||||
uploadAvatar: (image: File) => Promise<void>;
|
||||
|
||||
verifying: boolean;
|
||||
verify: () => Promise<void>;
|
||||
|
||||
setRedirect: (redirect: string) => void;
|
||||
}
|
||||
|
||||
export const useVerify = create<IVerifyState>((set) => ({
|
||||
export interface IVerifyActions {
|
||||
loadStep: (profile: UserProfile) => void;
|
||||
requestOTP: () => Promise<void>;
|
||||
confirmOTP: (req: ConfirmEmailRequest) => Promise<void>;
|
||||
uploadAvatar: (image: File) => Promise<void>;
|
||||
verify: () => Promise<void>;
|
||||
setRedirect: (redirect: string) => void;
|
||||
reset: () => void;
|
||||
}
|
||||
|
||||
const initialState: IVerifyState = {
|
||||
step: null,
|
||||
redirect: null,
|
||||
|
||||
@ -43,6 +40,12 @@ export const useVerify = create<IVerifyState>((set) => ({
|
||||
confirming: false,
|
||||
uploading: false,
|
||||
verifying: false,
|
||||
};
|
||||
|
||||
export const useVerify = create<IVerifyState & IVerifyActions>((set, get) => ({
|
||||
...initialState,
|
||||
|
||||
reset: () => set(initialState),
|
||||
|
||||
loadStep: (profile) => {
|
||||
if (!profile.email_verified) {
|
||||
@ -116,6 +119,7 @@ export const useVerify = create<IVerifyState>((set) => ({
|
||||
console.log("ERR: Failed to finish verification:", err);
|
||||
} finally {
|
||||
set({ verifying: false });
|
||||
get().reset();
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
Reference in New Issue
Block a user