From b59a6c75715bf22db4f5a13ca028d52451eb828a Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Thu, 8 Aug 2024 10:46:39 -0500 Subject: [PATCH] fix: update profile interests type to be optional and add guards --- components/organisms/TopNav/top-nav.tsx | 2 +- components/organisms/UserSettingsPage/user-settings-page.tsx | 2 +- components/shared/AppSidebar/AppSidebar.tsx | 2 +- next-types.d.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/organisms/TopNav/top-nav.tsx b/components/organisms/TopNav/top-nav.tsx index a219623f4..7b4d09ac5 100644 --- a/components/organisms/TopNav/top-nav.tsx +++ b/components/organisms/TopNav/top-nav.tsx @@ -44,7 +44,7 @@ const TopNav = () => { const Nav = ({ className }: { className?: string }) => { const { user } = useSupabaseAuth(); const { data: gitHubUser } = useFetchUser(user?.user_metadata.user_name); - const userInterest = gitHubUser?.interests.split(",")[0] || "javascript"; + const userInterest = gitHubUser?.interests?.split(",")[0] || "javascript"; const router = useRouter(); const explorePageUrlPattern = /^(\/explore\/topic).*\/(dashboard|reports|contributors|activity).*/g; diff --git a/components/organisms/UserSettingsPage/user-settings-page.tsx b/components/organisms/UserSettingsPage/user-settings-page.tsx index a8ae6195c..d6d1e68c5 100644 --- a/components/organisms/UserSettingsPage/user-settings-page.tsx +++ b/components/organisms/UserSettingsPage/user-settings-page.tsx @@ -143,7 +143,7 @@ const UserSettingsPage = ({ user }: UserSettingsPageProps) => { receive_collaboration: insightsUser?.receive_collaboration, receive_product_updates: insightsUser?.receive_product_updates, }); - setSelectedInterest(insightsUser?.interests?.split(",")); + setSelectedInterest(insightsUser?.interests?.split(",") || []); setDisplayLocalTime(insightsUser?.display_local_time); setTimezone(insightsUser?.timezone || ""); } diff --git a/components/shared/AppSidebar/AppSidebar.tsx b/components/shared/AppSidebar/AppSidebar.tsx index 086e7afff..9d11df0d9 100644 --- a/components/shared/AppSidebar/AppSidebar.tsx +++ b/components/shared/AppSidebar/AppSidebar.tsx @@ -87,7 +87,7 @@ export const AppSideBar = ({ workspaceId, hideSidebar, sidebarCollapsed }: AppSi }); const { data: gitHubUser } = useFetchUser(user?.user_metadata.user_name); - const userInterest = gitHubUser?.interests.split(",")[0] || "javascript"; + const userInterest = gitHubUser?.interests?.split(",")[0] || "javascript"; return ( // TODO: get rid of the z-index. There is grid content like the avatars and paged data text that bleed through the sidebar atm. diff --git a/next-types.d.ts b/next-types.d.ts index 58233b5c7..697e420ac 100644 --- a/next-types.d.ts +++ b/next-types.d.ts @@ -337,7 +337,7 @@ interface DbUser { readonly location: string; readonly display_local_time: boolean; readonly name: string; - readonly interests: string; + readonly interests?: string; readonly receive_collaboration: boolean; readonly display_email: boolean; readonly timezone: string;