Skip to content

Commit

Permalink
chore: fix initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Jun 3, 2024
1 parent 769b474 commit e0e4a1a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion frontend/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function App() {
// Redirect to sign up page if no instance owner.
useEffect(() => {
if (!workspaceStore.profile.owner) {
navigateTo("/auth/signup");
navigateTo("/auth/signup", {
replace: true,
});
}
}, [workspaceStore.profile]);

Expand Down
4 changes: 3 additions & 1 deletion frontend/web/src/layouts/CommonContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const CommonContextProvider = ({ children }: { children: React.ReactNode }) => {
useEffect(() => {
(async () => {
try {
await Promise.all([workspaceStore.fetchWorkspaceProfile(), workspaceStore.fetchWorkspaceSetting(), userStore.fetchCurrentUser()]);
await workspaceStore.fetchWorkspaceProfile();
await workspaceStore.fetchWorkspaceSetting();
await userStore.fetchCurrentUser();
} catch (error) {
// Do nothing.
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/web/src/stores/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ interface WorkspaceState {
fetchWorkspaceSetting: () => Promise<WorkspaceSetting>;
}

const useWorkspaceStore = create<WorkspaceState>()((set) => ({
const useWorkspaceStore = create<WorkspaceState>()((set, get) => ({
profile: WorkspaceProfile.fromPartial({}),
setting: WorkspaceSetting.fromPartial({}),
fetchWorkspaceProfile: async () => {
const workspaceProfile = (await workspaceServiceClient.getWorkspaceProfile({})).profile as WorkspaceProfile;
set({ profile: workspaceProfile });
set({ ...get(), profile: workspaceProfile });
return workspaceProfile;
},
fetchWorkspaceSetting: async () => {
const workspaceSetting = (await workspaceServiceClient.getWorkspaceSetting({})).setting as WorkspaceSetting;
set({ setting: workspaceSetting });
set({ ...get(), setting: workspaceSetting });
return workspaceSetting;
},
}));
Expand Down

0 comments on commit e0e4a1a

Please sign in to comment.