Skip to content

Commit

Permalink
clients/web: remove User.username
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Oct 28, 2024
1 parent cc02dc9 commit 9129c91
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function Page({ params }: { params: { id: string } }) {
</div>
{r.user && (
<div>
<span className="underline">{r.user.username}</span> [user]
<span className="underline">{r.user.public_name}</span> [user]
</div>
)}
{r.organization && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<DashboardBody>
Expand All @@ -41,15 +41,15 @@ export default function ClientPage() {
</TableHeader>
<TableBody>
{sortedMembers.map((m) => (
<TableRow key={m.github_username + m.name}>
<TableRow key={m.email}>
<TableCell className="font-medium ">
<div className="inline-flex items-center gap-2">
<Avatar
className="h-8 w-8"
avatar_url={m.avatar_url}
name={m.name}
name={m.email}
/>
<span className="whitespace-nowrap">{m.name}</span>
<span className="whitespace-nowrap">{m.email}</span>
</div>
</TableCell>
</TableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ const AuthorizePage = ({
<Avatar
className="h-8 w-8"
avatar_url={sub.avatar_url}
name={sub.username}
name={sub.email}
/>
{sub.username}
{sub.email}
</div>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ const AccountAssociations: React.FC<AccountAssociationsProps> = ({
() =>
account.users.reduce<string[]>(
(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],
Expand Down
22 changes: 14 additions & 8 deletions clients/apps/web/src/components/Backoffice/RewardsPending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -274,18 +275,23 @@ const Pledges = () => {
</div>
{r.user && (
<>
<img className="h-6 w-6" src={r.user.avatar_url} />
<div className="underline">{r.user.username}</div>
<Avatar
avatar_url={r.user.avatar_url}
name={r.user.public_name}
className="h-6 w-6"
/>
<div className="underline">
{r.user.public_name}
</div>
</>
)}
{r.organization && (
<>
{r.organization.avatar_url && (
<img
className="h-6 w-6"
src={r.organization.avatar_url}
/>
)}
<Avatar
avatar_url={r.organization.avatar_url}
name={r.organization.name}
className="h-6 w-6"
/>
<div className="underline">
{r.organization.name}
</div>
Expand Down
22 changes: 10 additions & 12 deletions clients/apps/web/src/components/Finance/ListRewards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -129,28 +130,25 @@ const List = (props: {
{showReceiver && (
<td className="dark:text-polar-400 whitespace-nowrap py-3 pr-3 text-sm text-gray-500">
<div className="flex items-center gap-1 ">
{t.user?.avatar_url && (
<img
src={t.user?.avatar_url}
{t.user && (
<Avatar
avatar_url={t.user.avatar_url}
name={t.user.public_name}
className="h-6 w-6 rounded-full"
/>
)}
<a
href={`https://github.com/${t.user?.username}`}
className="text-blue-500"
>
@{t.user?.username || 'Unknown'}
</a>
@{t.user?.public_name || 'Unknown'}
</div>
</td>
)}

{showBacker && (
<td className="dark:text-polar-400 whitespace-nowrap py-3 pr-3 text-sm text-gray-500">
<div className="flex items-center gap-1 ">
{t.pledge.pledger?.avatar_url && (
<img
src={t.pledge.pledger?.avatar_url}
{t.pledge.pledger && (
<Avatar
avatar_url={t.pledge.pledger.avatar_url}
name={t.pledge.pledger.name}
className="h-6 w-6 rounded-full"
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion clients/apps/web/src/components/Finance/SplitNotify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ _If you already have a Polar account setup, you don't need to do anything._
<div className="flex flex-row items-center gap-4">
<Avatar
avatar_url={props.user.avatar_url}
name={props.user.username}
name={props.user.email}
/>
<span className="dark:text-polar-200 text-gray-500">
Comment will be posted on your behalf to issue{' '}
Expand Down
28 changes: 14 additions & 14 deletions clients/apps/web/src/components/Issues/IssueListItem.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,17 +424,17 @@ 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,
},
{
...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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
},
},
Expand All @@ -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/',
Expand All @@ -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/',
Expand Down
10 changes: 5 additions & 5 deletions clients/apps/web/src/components/Issues/IssuePromotionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useAuth } from '@/hooks'
import { usePostHog } from '@/hooks/posthog'
import {
useBadgeWithComment,
useIssueAddComment,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
})
}

Expand Down Expand Up @@ -316,7 +316,7 @@ const PostCommentForm = (props: {
<div className="mt-3 flex flex-1 space-x-2">
{props.user.avatar_url && (
<Image
alt={`Avatar of ${props.user.username}`}
alt={`Avatar of ${props.user.email}`}
src={props.user.avatar_url}
height={200}
width={200}
Expand Down Expand Up @@ -623,9 +623,9 @@ const RewardsTab = (props: { issue: Issue; user: UserRead }) => {
<Avatar
className="h-6 w-6"
avatar_url={props.user.avatar_url}
name={props.user.username}
name={props.user.email}
/>
<div className="text-sm">@{props.user.username}</div>
<div className="text-sm">{props.user.email}</div>
</div>

<MoneyInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const DashboardProfileDropdown = ({ className = '' }) => {
avatar_url: currentOrg.avatar_url,
} as const)
: ({
name: loggedUser.username,
name: loggedUser.email,
avatar_url: loggedUser.avatar_url,
} as const)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const PublicProfileDropdown = ({
>
<Avatar
className="h-9 w-9"
name={loggedUser.username}
name={loggedUser.email}
avatar_url={loggedUser.avatar_url}
/>
</div>
Expand All @@ -78,7 +78,7 @@ const PublicProfileDropdown = ({
>
<ListItem current={true}>
<Profile
name={loggedUser.username}
name={loggedUser.email}
avatar_url={loggedUser.avatar_url}
/>
</ListItem>
Expand Down
12 changes: 4 additions & 8 deletions clients/apps/web/src/components/Pledge/OrganizationSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -91,11 +91,7 @@ const OrganizationSelect = ({
{attributePledgeTo ? (
<SelectValue placeholder={`${attributePledgeTo.slug}`} />
) : (
<SelectValue
placeholder={`Yourself (${
currentUser?.username || currentUser?.email
})`}
/>
<SelectValue placeholder={`Yourself (${currentUser?.email})`} />
)}
</SelectTrigger>

Expand All @@ -113,9 +109,9 @@ const OrganizationSelect = ({
<div className="flex items-center space-x-2">
<Avatar
avatar_url={currentUser.avatar_url}
name={currentUser.username ?? ''}
name={currentUser.email}
/>
<span>{currentUser.username}</span>
<span>{currentUser.email}</span>
</div>
</SelectItem>
) : null}
Expand Down
3 changes: 1 addition & 2 deletions clients/apps/web/src/hooks/auth.ts
Original file line number Diff line number Diff line change
@@ -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 = (): {
Expand Down Expand Up @@ -33,7 +33,6 @@ export const useAuth = (): {
Sentry.setUser({
id: currentUser.id,
email: currentUser.email,
username: currentUser.username,
})

posthog.identify(currentUser)
Expand Down
8 changes: 3 additions & 5 deletions clients/apps/web/src/hooks/posthog.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -52,7 +52,6 @@ type Verb =
| 'open'
| 'close'


export type EventName = `${Surface}:${Category}:${Noun}:${Verb}`

export interface PolarHog {
Expand All @@ -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,
})
}
Expand All @@ -100,6 +98,6 @@ export const usePostHog = (): PolarHog => {
capture,
identify,
isFeatureEnabled,
logout
logout,
}
}
Loading

0 comments on commit 9129c91

Please sign in to comment.