From 05a973ff090a49da5f0d2b45bfc2c68d4ff7fca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Sun, 1 Oct 2023 10:30:26 +0100 Subject: [PATCH] fix: Use get() instead of 'this' in Zustand stores (#2250) --- editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts | 5 ++--- editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts | 4 ++-- editor.planx.uk/src/routes/views/team.tsx | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts index b4c49bc0c3..d09d8b29df 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/team.ts @@ -54,7 +54,7 @@ export const teamStore: StateCreator = ( boundaryBBox: get().boundaryBBox, }), - async initTeamStore(teamSlugFromURLParams) { + initTeamStore: async (teamSlugFromURLParams) => { const slug = teamSlugFromURLParams || await getTeamFromDomain(window.location.hostname) const { data } = await client.query({ query: gql` @@ -86,7 +86,6 @@ export const teamStore: StateCreator = ( const team = data.teams[0]; if (!team) throw new Error("Team not found"); - - this.setTeam(team); + get().setTeam(team); }, }); diff --git a/editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts b/editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts index 8191b184f2..6e8a202b30 100644 --- a/editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts +++ b/editor.planx.uk/src/pages/FlowEditor/lib/store/user.ts @@ -59,7 +59,7 @@ export const userStore: StateCreator = ( ); }, - async initUserStore(jwt: string) { + initUserStore: async (jwt: string) => { const email = (jwtDecode(jwt) as any)["email"]; const users = await client.query({ query: gql` @@ -87,6 +87,6 @@ export const userStore: StateCreator = ( const user: User = users.data.users[0]; if (!user) throw new Error(`Failed to get user ${email}`); - this.setUser(user); + get().setUser(user); }, }); diff --git a/editor.planx.uk/src/routes/views/team.tsx b/editor.planx.uk/src/routes/views/team.tsx index e6f7d2f5b7..453a8e7763 100644 --- a/editor.planx.uk/src/routes/views/team.tsx +++ b/editor.planx.uk/src/routes/views/team.tsx @@ -13,7 +13,7 @@ export const teamView = async (req: NaviRequest) => { try { await initTeamStore(req.params.team); } catch (error) { - throw new NotFoundError("Team not found"); + throw new NotFoundError(`Team not found: ${error}`); } }