mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-10-27 08:14:30 -04:00
refactored signup flow for entire registration process. Utilized seed data option for optional seeding of Foods, Units, and Labels. Localized registration page.
67 lines
1.1 KiB
TypeScript
67 lines
1.1 KiB
TypeScript
import { reactive } from "@nuxtjs/composition-api";
|
|
|
|
export enum States {
|
|
Initial,
|
|
ProvideToken,
|
|
ProvideGroupDetails,
|
|
ProvideCredentials,
|
|
ProvideAccountDetails,
|
|
SelectGroupOptions,
|
|
Confirmation,
|
|
}
|
|
|
|
export enum RegistrationType {
|
|
Unknown,
|
|
JoinGroup,
|
|
CreateGroup,
|
|
InitialGroup,
|
|
}
|
|
|
|
interface Context {
|
|
state: States;
|
|
type: RegistrationType;
|
|
}
|
|
|
|
interface RegistrationContext {
|
|
ctx: Context;
|
|
setState(state: States): void;
|
|
setType(type: RegistrationType): void;
|
|
back(): void;
|
|
}
|
|
|
|
export function useRegistration(): RegistrationContext {
|
|
const context = reactive({
|
|
state: States.Initial,
|
|
type: RegistrationType.Unknown,
|
|
history: [
|
|
{
|
|
state: States.Initial,
|
|
},
|
|
],
|
|
});
|
|
|
|
function saveHistory() {
|
|
context.history.push({
|
|
state: context.state,
|
|
});
|
|
}
|
|
|
|
const back = () => {
|
|
const last = context.history.pop();
|
|
if (last) {
|
|
context.state = last.state;
|
|
}
|
|
};
|
|
|
|
const setState = (state: States) => {
|
|
saveHistory();
|
|
context.state = state;
|
|
};
|
|
|
|
const setType = (t: RegistrationType) => {
|
|
context.type = t;
|
|
};
|
|
|
|
return { ctx: context, setType, setState, back };
|
|
}
|