From 9129c919430ca56be9e83be773f4598afe7bc694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Voron?= Date: Mon, 28 Oct 2024 17:19:45 +0100 Subject: [PATCH] clients/web: remove User.username --- .../app/(main)/backoffice/issue/[id]/page.tsx | 2 +- .../(header)/members/ClientPage.tsx | 8 +++--- .../(main)/oauth2/authorize/AuthorizePage.tsx | 4 +-- .../Accounts/AccountAssociations.tsx | 4 +-- .../components/Backoffice/RewardsPending.tsx | 22 +++++++++------ .../src/components/Finance/ListRewards.tsx | 22 +++++++-------- .../src/components/Finance/SplitNotify.tsx | 2 +- .../Issues/IssueListItem.stories.tsx | 28 +++++++++---------- .../components/Issues/IssuePromotionModal.tsx | 10 +++---- .../Navigation/DashboardProfileDropdown.tsx | 2 +- .../Navigation/PublicProfileDropdown.tsx | 4 +-- .../components/Pledge/OrganizationSelect.tsx | 12 +++----- clients/apps/web/src/hooks/auth.ts | 3 +- clients/apps/web/src/hooks/posthog.ts | 8 ++---- clients/apps/web/src/hooks/team.ts | 2 +- .../web/src/stories/FinancePage.stories.tsx | 2 +- .../stories/FinanceRewardsList.stories.tsx | 2 +- clients/apps/web/src/utils/testdata.ts | 1 - 18 files changed, 67 insertions(+), 71 deletions(-) diff --git a/clients/apps/web/src/app/(main)/backoffice/issue/[id]/page.tsx b/clients/apps/web/src/app/(main)/backoffice/issue/[id]/page.tsx index d9834d1f14..04360970cf 100644 --- a/clients/apps/web/src/app/(main)/backoffice/issue/[id]/page.tsx +++ b/clients/apps/web/src/app/(main)/backoffice/issue/[id]/page.tsx @@ -76,7 +76,7 @@ export default function Page({ params }: { params: { id: string } }) { {r.user && (
- {r.user.username} [user] + {r.user.public_name} [user]
)} {r.organization && ( diff --git a/clients/apps/web/src/app/(main)/dashboard/[organization]/(header)/members/ClientPage.tsx b/clients/apps/web/src/app/(main)/dashboard/[organization]/(header)/members/ClientPage.tsx index 926a3e2d7f..5ea4accb58 100644 --- a/clients/apps/web/src/app/(main)/dashboard/[organization]/(header)/members/ClientPage.tsx +++ b/clients/apps/web/src/app/(main)/dashboard/[organization]/(header)/members/ClientPage.tsx @@ -21,7 +21,7 @@ export default function ClientPage() { const members = useListOrganizationMembers(org.id) const mems = members.data?.items || [] - const sortedMembers = mems.sort((a, b) => a.name.localeCompare(b.name)) + const sortedMembers = mems.sort((a, b) => a.email.localeCompare(b.email)) return ( @@ -41,15 +41,15 @@ export default function ClientPage() { {sortedMembers.map((m) => ( - +
- {m.name} + {m.email}
diff --git a/clients/apps/web/src/app/(main)/oauth2/authorize/AuthorizePage.tsx b/clients/apps/web/src/app/(main)/oauth2/authorize/AuthorizePage.tsx index 824a1b7e2c..346b6a8f5c 100644 --- a/clients/apps/web/src/app/(main)/oauth2/authorize/AuthorizePage.tsx +++ b/clients/apps/web/src/app/(main)/oauth2/authorize/AuthorizePage.tsx @@ -80,9 +80,9 @@ const AuthorizePage = ({ - {sub.username} + {sub.email} )} diff --git a/clients/apps/web/src/components/Accounts/AccountAssociations.tsx b/clients/apps/web/src/components/Accounts/AccountAssociations.tsx index 8c155326a7..2152a3ab36 100644 --- a/clients/apps/web/src/components/Accounts/AccountAssociations.tsx +++ b/clients/apps/web/src/components/Accounts/AccountAssociations.tsx @@ -14,9 +14,9 @@ const AccountAssociations: React.FC = ({ () => account.users.reduce( (array, user) => - array.some((value) => value === user.username) + array.some((value) => value === user.email) ? array - : [...array, user.username], + : [...array, user.email], account.organizations.map(({ name }) => name), ), [account], diff --git a/clients/apps/web/src/components/Backoffice/RewardsPending.tsx b/clients/apps/web/src/components/Backoffice/RewardsPending.tsx index 01b38af5ec..3bbd3bbd50 100644 --- a/clients/apps/web/src/components/Backoffice/RewardsPending.tsx +++ b/clients/apps/web/src/components/Backoffice/RewardsPending.tsx @@ -14,6 +14,7 @@ import { } from '@heroicons/react/20/solid' import { BackofficeReward, PledgeState, PledgeType } from '@polar-sh/sdk' import Link from 'next/link' +import Avatar from 'polarkit/components/ui/atoms/avatar' import Button from 'polarkit/components/ui/atoms/button' import { formatCurrencyAndAmount, @@ -274,18 +275,23 @@ const Pledges = () => { {r.user && ( <> - -
{r.user.username}
+ +
+ {r.user.public_name} +
)} {r.organization && ( <> - {r.organization.avatar_url && ( - - )} +
{r.organization.name}
diff --git a/clients/apps/web/src/components/Finance/ListRewards.tsx b/clients/apps/web/src/components/Finance/ListRewards.tsx index 9a7aa83073..bd6828be1e 100644 --- a/clients/apps/web/src/components/Finance/ListRewards.tsx +++ b/clients/apps/web/src/components/Finance/ListRewards.tsx @@ -5,6 +5,7 @@ import Icon from '@/components/Icons/Icon' import { githubIssueLink } from '@/utils/github' import { dateOrString } from '@/utils/time' import { PledgeState, PledgeType, Reward, RewardState } from '@polar-sh/sdk' +import Avatar from 'polarkit/components/ui/atoms/avatar' import { formatCurrencyAndAmount, getCentsInDollarString, @@ -129,18 +130,14 @@ const List = (props: { {showReceiver && (
- {t.user?.avatar_url && ( - )} - - @{t.user?.username || 'Unknown'} - + @{t.user?.public_name || 'Unknown'}
)} @@ -148,9 +145,10 @@ const List = (props: { {showBacker && (
- {t.pledge.pledger?.avatar_url && ( - )} diff --git a/clients/apps/web/src/components/Finance/SplitNotify.tsx b/clients/apps/web/src/components/Finance/SplitNotify.tsx index 3d9404c48a..8f35773c03 100644 --- a/clients/apps/web/src/components/Finance/SplitNotify.tsx +++ b/clients/apps/web/src/components/Finance/SplitNotify.tsx @@ -91,7 +91,7 @@ _If you already have a Polar account setup, you don't need to do anything._
Comment will be posted on your behalf to issue{' '} diff --git a/clients/apps/web/src/components/Issues/IssueListItem.stories.tsx b/clients/apps/web/src/components/Issues/IssueListItem.stories.tsx index 3ff85bd68a..c7db3ad264 100644 --- a/clients/apps/web/src/components/Issues/IssueListItem.stories.tsx +++ b/clients/apps/web/src/components/Issues/IssueListItem.stories.tsx @@ -424,8 +424,8 @@ export const SelfSummaryFundingGoal: Story = { { ...pledgePublicAPI, pledger: { - name: user.username, - github_username: user.username, + name: user.email, + github_username: 'test', avatar_url: user.avatar_url, }, authed_can_admin_sender: true, @@ -433,8 +433,8 @@ export const SelfSummaryFundingGoal: Story = { { ...pledgePublicAPI, pledger: { - name: user.username, - github_username: user.username, + name: user.email, + github_username: 'test', avatar_url: user.avatar_url, }, authed_can_admin_sender: true, @@ -469,8 +469,8 @@ export const SelfSummaryNoGoal: Story = { { ...pledgePublicAPI, pledger: { - name: user.username, - github_username: user.username, + name: user.email, + github_username: 'test', avatar_url: user.avatar_url, }, authed_can_admin_sender: true, @@ -488,8 +488,8 @@ export const SelfSummaryNoGoal: Story = { { ...pledgePublicAPI, pledger: { - name: user.username, - github_username: user.username, + name: user.email, + github_username: 'test', avatar_url: user.avatar_url, }, authed_can_admin_sender: true, @@ -530,8 +530,8 @@ export const OrganizationPledgeWithCreatedBy: Story = { }, authed_can_admin_sender: true, created_by: { - name: user.username, - github_username: user.username, + name: user.email, + github_username: 'test', avatar_url: user.avatar_url, }, }, @@ -555,8 +555,8 @@ export const OrganizationPledgeWithInvoice: Story = { }, authed_can_admin_sender: true, created_by: { - name: user.username, - github_username: user.username, + name: user.email, + github_username: 'test', avatar_url: user.avatar_url, }, hosted_invoice_url: 'http://example.com/', @@ -570,8 +570,8 @@ export const OrganizationPledgeWithInvoice: Story = { }, authed_can_admin_sender: true, created_by: { - name: user.username, - github_username: user.username, + name: user.email, + github_username: 'test', avatar_url: user.avatar_url, }, hosted_invoice_url: 'http://example.com/', diff --git a/clients/apps/web/src/components/Issues/IssuePromotionModal.tsx b/clients/apps/web/src/components/Issues/IssuePromotionModal.tsx index be566b1a3e..24f66927f8 100644 --- a/clients/apps/web/src/components/Issues/IssuePromotionModal.tsx +++ b/clients/apps/web/src/components/Issues/IssuePromotionModal.tsx @@ -1,4 +1,5 @@ import { useAuth } from '@/hooks' +import { usePostHog } from '@/hooks/posthog' import { useBadgeWithComment, useIssueAddComment, @@ -38,7 +39,6 @@ import { ModalHeader, Modal as ModernModal } from '../Modal' import { useModal } from '../Modal/useModal' import BadgeMessageForm from './BadgeMessageForm' import PublicRewardsSetting from './UpfrontRewards' -import { usePostHog } from '@/hooks/posthog' const isIssueBadged = (issue: Issue): boolean => { return issue.pledge_badge_currently_embedded @@ -132,7 +132,7 @@ export const AddBadgeButton = (props: { issue: Issue }) => { organization_name: props.issue.repository.organization.name, repository_name: props.issue.repository.name, issue_number: props.issue.number, - funding_goal: amount + funding_goal: amount, }) } @@ -316,7 +316,7 @@ const PostCommentForm = (props: {
{props.user.avatar_url && ( {`Avatar { -
@{props.user.username}
+
{props.user.email}
{ avatar_url: currentOrg.avatar_url, } as const) : ({ - name: loggedUser.username, + name: loggedUser.email, avatar_url: loggedUser.avatar_url, } as const) diff --git a/clients/apps/web/src/components/Navigation/PublicProfileDropdown.tsx b/clients/apps/web/src/components/Navigation/PublicProfileDropdown.tsx index 9074ea006b..c07a2b3b93 100644 --- a/clients/apps/web/src/components/Navigation/PublicProfileDropdown.tsx +++ b/clients/apps/web/src/components/Navigation/PublicProfileDropdown.tsx @@ -60,7 +60,7 @@ const PublicProfileDropdown = ({ >
@@ -78,7 +78,7 @@ const PublicProfileDropdown = ({ > diff --git a/clients/apps/web/src/components/Pledge/OrganizationSelect.tsx b/clients/apps/web/src/components/Pledge/OrganizationSelect.tsx index f9f9c7f7a3..3af87d6418 100644 --- a/clients/apps/web/src/components/Pledge/OrganizationSelect.tsx +++ b/clients/apps/web/src/components/Pledge/OrganizationSelect.tsx @@ -30,7 +30,7 @@ const OrganizationSelect = ({ >(undefined) const canSelectOrganizations = organizations - .filter((o) => o.slug !== currentUser?.username) + .filter((o) => o.slug !== currentUser?.email) .filter((o) => { if (organizationFilter) { return organizationFilter(o) @@ -91,11 +91,7 @@ const OrganizationSelect = ({ {attributePledgeTo ? ( ) : ( - + )} @@ -113,9 +109,9 @@ const OrganizationSelect = ({
- {currentUser.username} + {currentUser.email}
) : null} diff --git a/clients/apps/web/src/hooks/auth.ts b/clients/apps/web/src/hooks/auth.ts index 2ba9274f56..21ce2149fa 100644 --- a/clients/apps/web/src/hooks/auth.ts +++ b/clients/apps/web/src/hooks/auth.ts @@ -1,9 +1,9 @@ +import { usePostHog } from '@/hooks/posthog' import { AuthContext } from '@/providers/auth' import { api } from '@/utils/api' import { CONFIG } from '@/utils/config' import { Organization, UserRead } from '@polar-sh/sdk' import * as Sentry from '@sentry/nextjs' -import { usePostHog } from '@/hooks/posthog' import { useCallback, useContext, useEffect } from 'react' export const useAuth = (): { @@ -33,7 +33,6 @@ export const useAuth = (): { Sentry.setUser({ id: currentUser.id, email: currentUser.email, - username: currentUser.username, }) posthog.identify(currentUser) diff --git a/clients/apps/web/src/hooks/posthog.ts b/clients/apps/web/src/hooks/posthog.ts index 06be02a8dc..7142826092 100644 --- a/clients/apps/web/src/hooks/posthog.ts +++ b/clients/apps/web/src/hooks/posthog.ts @@ -1,9 +1,9 @@ 'use client' import { CONFIG } from '@/utils/config' -import { Properties, PostHog } from 'posthog-js' -import { usePostHog as useOfficialPostHog} from 'posthog-js/react' import { UserRead } from '@polar-sh/sdk' +import { PostHog, Properties } from 'posthog-js' +import { usePostHog as useOfficialPostHog } from 'posthog-js/react' // https://posthog.com/product-engineers/5-ways-to-improve-analytics-data#suggested-naming-guide @@ -52,7 +52,6 @@ type Verb = | 'open' | 'close' - export type EventName = `${Surface}:${Category}:${Noun}:${Verb}` export interface PolarHog { @@ -76,7 +75,6 @@ export const usePostHog = (): PolarHog => { const posthogId = `user:${user.id}` if (posthog.get_distinct_id() !== posthogId) { posthog.identify(posthogId, { - username: user.username, email: user.email, }) } @@ -100,6 +98,6 @@ export const usePostHog = (): PolarHog => { capture, identify, isFeatureEnabled, - logout + logout, } } diff --git a/clients/apps/web/src/hooks/team.ts b/clients/apps/web/src/hooks/team.ts index 63d6c565f6..b9d57538f5 100644 --- a/clients/apps/web/src/hooks/team.ts +++ b/clients/apps/web/src/hooks/team.ts @@ -12,7 +12,7 @@ export const useListTeams = () => { // Filter out the users own organization if it exists. // This organiztaion can not have extra members, and can not be a "Team". const allTeams = allOrganizations.filter( - (o) => o.slug !== currentUser?.username, + (o) => o.slug !== currentUser?.email, ) setTeams(allTeams) diff --git a/clients/apps/web/src/stories/FinancePage.stories.tsx b/clients/apps/web/src/stories/FinancePage.stories.tsx index 6b12930c77..acc072bbf6 100644 --- a/clients/apps/web/src/stories/FinancePage.stories.tsx +++ b/clients/apps/web/src/stories/FinancePage.stories.tsx @@ -60,7 +60,7 @@ let all_pledge_states: Pledge[] = Object.values(PledgeState).map( const paidRewardUser: Reward = { pledge: pledge, user: { - username: 'petterheterjag', + public_name: 'Petter', avatar_url: 'https://avatars.githubusercontent.com/u/1426460?v=4', }, organization: undefined, diff --git a/clients/apps/web/src/stories/FinanceRewardsList.stories.tsx b/clients/apps/web/src/stories/FinanceRewardsList.stories.tsx index 2eb1db302c..ca8c6fcc68 100644 --- a/clients/apps/web/src/stories/FinanceRewardsList.stories.tsx +++ b/clients/apps/web/src/stories/FinanceRewardsList.stories.tsx @@ -35,7 +35,7 @@ const pledge: Pledge = { const reward: Reward = { pledge, user: { - username: 'foobar', + public_name: 'foobar', avatar_url: 'https://avatars.githubusercontent.com/u/4314092?s=200&v=4', }, amount: { amount: 800, currency: 'usd' }, diff --git a/clients/apps/web/src/utils/testdata.ts b/clients/apps/web/src/utils/testdata.ts index 6db452e157..1396fc1df9 100644 --- a/clients/apps/web/src/utils/testdata.ts +++ b/clients/apps/web/src/utils/testdata.ts @@ -69,7 +69,6 @@ export const org: Organization = { export const user: UserRead = { created_at: new Date('2023-01-01T00:00:00Z').toISOString(), modified_at: new Date('2023-01-01T09:00:00Z').toISOString(), - username: 'zegl', email: 'test@example.com', avatar_url: 'https://avatars.githubusercontent.com/u/47952?v=4', accepted_terms_of_service: true,