|
|
@@ -4,17 +4,23 @@ import { proxy } from "valtio";
|
|
|
import { derive, devtools } from "valtio/utils";
|
|
|
|
|
|
export type OnboardingStateType = {
|
|
|
+ [key: string]: unknown;
|
|
|
projectName: string;
|
|
|
// Null when is not setted yet.
|
|
|
isProvisionerEnabled: boolean | null;
|
|
|
userId: number | null;
|
|
|
+ // Check if it's the first project that will be created
|
|
|
+ isFirstProject: boolean | null;
|
|
|
};
|
|
|
|
|
|
-export const OnboardingState = proxy<OnboardingStateType>({
|
|
|
+const initialState: OnboardingStateType = {
|
|
|
projectName: "",
|
|
|
isProvisionerEnabled: null,
|
|
|
userId: null,
|
|
|
-});
|
|
|
+ isFirstProject: null,
|
|
|
+};
|
|
|
+
|
|
|
+export const OnboardingState = proxy<OnboardingStateType>(initialState);
|
|
|
|
|
|
devtools(OnboardingState, "Onboarding state");
|
|
|
|
|
|
@@ -28,6 +34,9 @@ export const actions = {
|
|
|
setUserId: (userId: number) => {
|
|
|
OnboardingState.userId = userId;
|
|
|
},
|
|
|
+ setIsFirstProject: (isFirstProject: boolean) => {
|
|
|
+ OnboardingState.isFirstProject = isFirstProject;
|
|
|
+ },
|
|
|
initFromGlobalContext: (context: Partial<ContextProps>) => {
|
|
|
const provisionerStatus = context?.capabilities?.provisioner;
|
|
|
|
|
|
@@ -43,5 +52,17 @@ export const actions = {
|
|
|
} else {
|
|
|
actions.setUserId(null);
|
|
|
}
|
|
|
+ if (context?.projects?.length >= 1) {
|
|
|
+ actions.setIsFirstProject(false);
|
|
|
+ } else {
|
|
|
+ actions.setIsFirstProject(true);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ clearState: () => {
|
|
|
+ Object.keys(OnboardingState).forEach((key) => {
|
|
|
+ if (key in initialState) {
|
|
|
+ OnboardingState[key] = initialState[key];
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
};
|