Skip to content

Commit

Permalink
Merge branch 'main' into donorEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
ZL-Asica committed Dec 6, 2024
2 parents 0aded02 + 805e3f2 commit 193d8f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
20 changes: 11 additions & 9 deletions src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@ const AppRoutes = () => {

const loading = useUserStore((state) => state.loading);
const user = useUserStore((state) => state.user);
const subscribeToProfiles = useOrganizationStore(
(state) => state.subscribeToProfiles
);
const error = useOrganizationStore((state) => state.error);

if (!loading && (!user || user.role !== 'organization')) {
const subscribeToProfiles = useOrganizationStore(
(state) => state.subscribeToProfiles
);
const error = useOrganizationStore((state) => state.error);

useEffect(() => {
useEffect(() => {
if (!loading && (!user || user.role !== 'organization')) {
const unsubscribe = subscribeToProfiles;

return () => unsubscribe && unsubscribe();
}, [subscribeToProfiles]);
}
}, [loading, user, subscribeToProfiles]);

useEffect(() => {
if (error) {
toast.error(error);
}
}
}, [error]);

return (
<Routes>
Expand Down
15 changes: 9 additions & 6 deletions src/stores/userStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ const useUserStore = create<UserState>()(
async (firebaseUser) => {
if (firebaseUser) {
const currentUser = get().user;
if (currentUser) {
await fetchEventsByIds(currentUser.joinedEvents);

if (currentUser && currentUser.joinedEvents?.length > 0) {
try {
await fetchEventsByIds(currentUser.joinedEvents);
} catch (error) {
console.error('Error fetching events:', error);
}
}
set({ user: currentUser || undefined });
} else {
set({ user: undefined });
const eventStore = useEventStore.getState();
eventStore.setEvents([]);
useEventStore.getState().setEvents([]);
}
set({ loading: false });
}
Expand Down Expand Up @@ -69,8 +74,6 @@ const useUserStore = create<UserState>()(
try {
set({ loading: true });
await logoutUser(navigate);
const eventStore = useEventStore.getState();
eventStore.setEvents([]);

set({ user: undefined, error: null });
} catch (error) {
Expand Down

0 comments on commit 193d8f8

Please sign in to comment.