From 3e67050d426555ebbb0956785281b915bbe05c39 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Wed, 1 Feb 2023 12:06:50 -0600 Subject: [PATCH 1/7] fix: connect more user settings to the API --- .../UserSettingsPage/user-settings-page.tsx | 35 +++++++++++++------ lib/hooks/update-user.ts | 6 ++-- next-types.d.ts | 2 +- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/components/organisms/UserSettingsPage/user-settings-page.tsx b/components/organisms/UserSettingsPage/user-settings-page.tsx index 69f6a9b9f..f4dbffcd7 100644 --- a/components/organisms/UserSettingsPage/user-settings-page.tsx +++ b/components/organisms/UserSettingsPage/user-settings-page.tsx @@ -30,6 +30,8 @@ const UserSettingsPage = ({ user }: userSettingsPageProps) => { const { data: insightsUser } = useFetchUser(user?.user_metadata.user_name); const [isValidEmail, setIsValidEmail] = useState(true); + const [displayLocalTime, setDisplayLocalTime] = useState(false); + const [timezone, setTimezone] = useState(''); const [userInfo, setUserInfo] = useState(); const [email, setEmail] = useState(userInfo?.email || user?.email); const [emailPreference, setEmailPreference] = useState({ @@ -55,7 +57,9 @@ const UserSettingsPage = ({ user }: userSettingsPageProps) => { // eslint-disable-next-line camelcase receive_collaboration: insightsUser?.receive_collaboration }); - setSelectedInterest(insightsUser?.interests.split(",")); + setSelectedInterest(insightsUser?.interests?.split(",")); + setDisplayLocalTime(insightsUser?.display_local_time); + setTimezone(insightsUser?.timezone) } fetchAuthSession(); }, [user, insightsUser]); @@ -88,10 +92,16 @@ const UserSettingsPage = ({ user }: userSettingsPageProps) => { ToastTrigger({ message: "An error occured!!!", type: "error" }); } }; + const handleUpdateProfile = async () => { const data = await updateUser({ - data: { email } + data: { + email, + display_local_time: displayLocalTime, + timezone + } }); + if (data) { ToastTrigger({ message: "Updated successfully", type: "success" }); } else { @@ -145,20 +155,20 @@ const UserSettingsPage = ({ user }: userSettingsPageProps) => { { placeholder="USA" label="Location" disabled - value={userInfo?.location || "Canada"} + value={userInfo?.location || "California"} />
- + setDisplayLocalTime(e.target.checked)} + /> Other users will see the time difference from their local time.
- setTimezone(e.target.value)}> Select time zone {timezones.map((timezone, index) => ( - + {timezone.text} ))} @@ -201,7 +216,7 @@ const UserSettingsPage = ({ user }: userSettingsPageProps) => { {interestArray.map((topic, index) => ( handleSelectInterest(topic)} - classNames={`${selectedInterest.includes(topic) && "bg-light-orange-10 text-white"}`} + classNames={`${(selectedInterest || []).includes(topic) && "bg-light-orange-10 text-white"}`} topic={topic} key={index} /> diff --git a/lib/hooks/update-user.ts b/lib/hooks/update-user.ts index e771cebfd..8ebae7a20 100644 --- a/lib/hooks/update-user.ts +++ b/lib/hooks/update-user.ts @@ -1,7 +1,7 @@ import { supabase } from "lib/utils/supabase"; interface useUpdateUserProps { - data: { email?: string; interests?: string[] }; + data: { email?: string; interests?: string[]; display_local_time?: boolean; timezone?: string }; params?: string; } @@ -14,10 +14,10 @@ const updateUser = async ({ data, params }: useUpdateUserProps) => { headers: { Accept: "application/json", "Content-Type": "application/json", - Authorization: `Bearer ${sessionToken}` + Authorization: `Bearer ${sessionToken}`, }, method: "PATCH", - body: JSON.stringify({ ...data }) + body: JSON.stringify({ ...data }), }); if (res.status === 200) { diff --git a/next-types.d.ts b/next-types.d.ts index a35dc8775..e573a14f0 100644 --- a/next-types.d.ts +++ b/next-types.d.ts @@ -130,5 +130,5 @@ interface DbUser { readonly interests: string; readonly receive_collaboration: boolean; readonly display_email: boolean; - + readonly timezone: string; } From 597d57a9dddcca51e33fecee9950737999428710 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Wed, 1 Feb 2023 12:14:22 -0600 Subject: [PATCH 2/7] chore: formatting --- components/organisms/UserSettingsPage/user-settings-page.tsx | 5 +++-- lib/hooks/update-user.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/components/organisms/UserSettingsPage/user-settings-page.tsx b/components/organisms/UserSettingsPage/user-settings-page.tsx index f4dbffcd7..69cd18e6a 100644 --- a/components/organisms/UserSettingsPage/user-settings-page.tsx +++ b/components/organisms/UserSettingsPage/user-settings-page.tsx @@ -31,7 +31,7 @@ const UserSettingsPage = ({ user }: userSettingsPageProps) => { const [isValidEmail, setIsValidEmail] = useState(true); const [displayLocalTime, setDisplayLocalTime] = useState(false); - const [timezone, setTimezone] = useState(''); + const [timezone, setTimezone] = useState(""); const [userInfo, setUserInfo] = useState(); const [email, setEmail] = useState(userInfo?.email || user?.email); const [emailPreference, setEmailPreference] = useState({ @@ -59,7 +59,7 @@ const UserSettingsPage = ({ user }: userSettingsPageProps) => { }); setSelectedInterest(insightsUser?.interests?.split(",")); setDisplayLocalTime(insightsUser?.display_local_time); - setTimezone(insightsUser?.timezone) + setTimezone(insightsUser?.timezone); } fetchAuthSession(); }, [user, insightsUser]); @@ -97,6 +97,7 @@ const UserSettingsPage = ({ user }: userSettingsPageProps) => { const data = await updateUser({ data: { email, + // eslint-disable-next-line camelcase display_local_time: displayLocalTime, timezone } diff --git a/lib/hooks/update-user.ts b/lib/hooks/update-user.ts index 8ebae7a20..678715ab5 100644 --- a/lib/hooks/update-user.ts +++ b/lib/hooks/update-user.ts @@ -14,10 +14,10 @@ const updateUser = async ({ data, params }: useUpdateUserProps) => { headers: { Accept: "application/json", "Content-Type": "application/json", - Authorization: `Bearer ${sessionToken}`, + Authorization: `Bearer ${sessionToken}` }, method: "PATCH", - body: JSON.stringify({ ...data }), + body: JSON.stringify({ ...data }) }); if (res.status === 200) { From 571286e4c3fa2ddc0739d8feaf6c9abcd2fce6ea Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Wed, 1 Feb 2023 12:38:25 -0600 Subject: [PATCH 3/7] fix: connect data to user profile --- .../contributor-profile-info.tsx | 14 +++++++++----- .../contributor-profile-page.tsx | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/components/molecules/ContributorProfileInfo/contributor-profile-info.tsx b/components/molecules/ContributorProfileInfo/contributor-profile-info.tsx index b036fc92d..2c1dcc4d0 100644 --- a/components/molecules/ContributorProfileInfo/contributor-profile-info.tsx +++ b/components/molecules/ContributorProfileInfo/contributor-profile-info.tsx @@ -16,6 +16,8 @@ interface ContributorProfileInfoProps { twitterUsername?: string; interests?: string; isConnected?: boolean; + timezone?: string; + displayLocalTime?: boolean; } const ContributorProfileInfo = ({ @@ -23,7 +25,9 @@ const ContributorProfileInfo = ({ twitterUsername, bio, interests, - isConnected + isConnected, + timezone, + displayLocalTime }: ContributorProfileInfoProps) => { const interestArray = interests?.split(","); @@ -43,7 +47,7 @@ const ContributorProfileInfo = ({ <> - UTC +1 + {timezone || "UTC+1"} @@ -64,14 +68,14 @@ const ContributorProfileInfo = ({ "I am an open source developer with a passion for music and video games. I strive to improve the open source community and am always looking for new ways to contribute."}

- + {displayLocalTime && Local time: 12:32 PM - + } - coming soon... + {twitterUsername || "coming soon..."} diff --git a/components/organisms/ContributorProfilePage/contributor-profile-page.tsx b/components/organisms/ContributorProfilePage/contributor-profile-page.tsx index 1f49d6457..4938efb7d 100644 --- a/components/organisms/ContributorProfilePage/contributor-profile-page.tsx +++ b/components/organisms/ContributorProfilePage/contributor-profile-page.tsx @@ -75,7 +75,7 @@ const ContributorProfilePage = ({ const isLoaded = !loading && !error; // eslint-disable-next-line camelcase - const { bio, location, interests, name, twitter_username } = user || {}; + const { bio, location, interests, name, twitter_username, timezone, display_local_time: displayLocalTime } = user || {}; return (
@@ -93,6 +93,8 @@ const ContributorProfilePage = ({ bio={bio} githubName={githubName} isConnected={!!user} + timezone={timezone} + displayLocalTime={displayLocalTime} />
From ec4d76deac8727314f838cf68237218c0bef8a17 Mon Sep 17 00:00:00 2001 From: Brandon Roberts Date: Wed, 1 Feb 2023 12:48:25 -0600 Subject: [PATCH 4/7] fix: use timezone value --- components/organisms/UserSettingsPage/user-settings-page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/organisms/UserSettingsPage/user-settings-page.tsx b/components/organisms/UserSettingsPage/user-settings-page.tsx index 69cd18e6a..f5bb70872 100644 --- a/components/organisms/UserSettingsPage/user-settings-page.tsx +++ b/components/organisms/UserSettingsPage/user-settings-page.tsx @@ -197,7 +197,7 @@ const UserSettingsPage = ({ user }: userSettingsPageProps) => {