Skip to content

Commit

Permalink
refactor(platform): Added avatars on secret and variable accordions (#…
Browse files Browse the repository at this point in the history
…751)

Co-authored-by: kriptonian1 <[email protected]>
Co-authored-by: Sawan Bhattacharya <[email protected]>
  • Loading branch information
3 people authored Feb 21, 2025
1 parent 4682c28 commit 5345925
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 22 deletions.
19 changes: 19 additions & 0 deletions apps/platform/src/components/common/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar'

interface AvatarProps {
name: string
src: string | null
className?: string
}

export default function AvatarComponent({ name, className, src }: AvatarProps) {
return (
<Avatar className={className ?? 'h-6 w-6'}>
<AvatarImage src={src === null ? undefined : src} />
<AvatarFallback className="font-semibold">
{name.charAt(0).toUpperCase() + name.slice(1, 2).toLowerCase()}
</AvatarFallback>
</Avatar>
)
}
14 changes: 12 additions & 2 deletions apps/platform/src/components/dashboard/secret/secretCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
editSecretOpenAtom,
selectedSecretAtom
} from '@/store'

import AvatarComponent from '@/components/common/avatar'
import { copyToClipboard } from '@/lib/clipboard'

interface SecretCardProps {
Expand Down Expand Up @@ -74,9 +76,17 @@ export default function SecretCard({
<AccordionTrigger
className="hover:no-underline"
rightChildren={
<div className="text-xs text-white/50">
<div className="flex items-center gap-x-4 text-xs text-white/50">
{dayjs(secret.updatedAt).toNow(true)} ago by{' '}
<span className="text-white">{secret.lastUpdatedBy.name}</span>
<div className="flex items-center gap-x-2">
<span className="text-white">
{secret.lastUpdatedBy.name}
</span>
<AvatarComponent
name={secret.lastUpdatedBy.name}
src={secret.lastUpdatedBy.profilePictureUrl}
/>
</div>
</div>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
AccordionItem,
AccordionTrigger
} from '@/components/ui/accordion'
import AvatarComponent from '@/components/common/avatar'
import { copyToClipboard } from '@/lib/clipboard'

export default function VariableCard(
Expand Down Expand Up @@ -68,11 +69,17 @@ export default function VariableCard(
<AccordionTrigger
className="hover:no-underline"
rightChildren={
<div className="text-xs text-white/50">
<div className="flex items-center gap-x-4 text-xs text-white/50">
{dayjs(variable.updatedAt).toNow(true)} ago by{' '}
<span className="text-white">
{variable.lastUpdatedBy.name}
</span>
<div className="flex items-center gap-x-2">
<span className="text-white">
{variable.lastUpdatedBy.name}
</span>
<AvatarComponent
name={variable.lastUpdatedBy.name}
src={variable.lastUpdatedBy.profilePictureUrl}
/>
</div>
</div>
}
>
Expand Down
12 changes: 5 additions & 7 deletions apps/platform/src/components/shared/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
import LineTab from '@/components/ui/line-tab'
import AvatarComponent from '@/components/common/avatar'
import { selectedProjectAtom, userAtom } from '@/store'

function Navbar(): React.JSX.Element {
Expand Down Expand Up @@ -120,12 +120,10 @@ function Navbar(): React.JSX.Element {
</>
) : (
<>
<Avatar>
<AvatarImage src={user.profilePictureUrl ?? ''} />
<AvatarFallback>
{user.name ? user.name.slice(0, 2) : ''}
</AvatarFallback>
</Avatar>
<AvatarComponent
name={user.name}
src={user.profilePictureUrl || ''}
/>
<span>{user.name}</span>
</>
)}
Expand Down
3 changes: 2 additions & 1 deletion packages/schema/src/secret/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export const SecretSchema = z.object({
projectId: BaseProjectSchema.shape.id,
lastUpdatedBy: z.object({
id: z.string(),
name: z.string()
name: z.string(),
profilePictureUrl: z.string().nullable()
})
}),
values: z.array(
Expand Down
3 changes: 2 additions & 1 deletion packages/schema/src/variable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const VariableSchema = z.object({
projectId: BaseProjectSchema.shape.id,
lastUpdatedBy: z.object({
id: z.string(),
name: z.string()
name: z.string(),
profilePictureUrl: z.string().nullable()
})
}),
values: z.array(
Expand Down
15 changes: 10 additions & 5 deletions packages/schema/tests/secret.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('Secret Schema Tests', () => {
projectId: 'project123',
lastUpdatedBy: {
id: 'user123',
name: 'John Doe'
name: 'John Doe',
profilePictureUrl: 'http://example.com/profile.jpg'
}
},
values: [
Expand Down Expand Up @@ -70,6 +71,7 @@ describe('Secret Schema Tests', () => {
lastUpdatedBy: {
id: 'user123',
name: 'John Doe'
// Missing profilePictureUrl
}
},
values: [
Expand All @@ -87,7 +89,7 @@ describe('Secret Schema Tests', () => {
]
})
expect(result.success).toBe(false)
expect(result.error?.issues).toHaveLength(5)
expect(result.error?.issues).toHaveLength(6)
})
})

Expand Down Expand Up @@ -141,7 +143,8 @@ describe('Secret Schema Tests', () => {
projectId: 'project123',
lastUpdatedBy: {
id: 'user123',
name: 'John Doe'
name: 'John Doe',
profilePictureUrl: 'http://example.com/profile.jpg'
}
},
values: [
Expand Down Expand Up @@ -180,6 +183,7 @@ describe('Secret Schema Tests', () => {
lastUpdatedBy: {
id: 'user123',
name: 'John Doe'
// Missing profilePictureUrl
}
},
values: [
Expand All @@ -197,7 +201,7 @@ describe('Secret Schema Tests', () => {
]
})
expect(result.success).toBe(false)
expect(result.error?.issues).toHaveLength(5)
expect(result.error?.issues).toHaveLength(6)
})
})

Expand Down Expand Up @@ -380,7 +384,8 @@ describe('Secret Schema Tests', () => {
projectId: 'project123',
lastUpdatedBy: {
id: 'user123',
name: 'John Doe'
name: 'John Doe',
profilePictureUrl: null
}
},
values: [
Expand Down
6 changes: 4 additions & 2 deletions packages/schema/tests/variable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('Variable Schema Tests', () => {
lastUpdatedBy: {
id: 'user123'
// Missing name
// Missing profilePictureUrl
}
},
values: [
Expand All @@ -121,7 +122,7 @@ describe('Variable Schema Tests', () => {
]
})
expect(result.success).toBe(false)
expect(result.error?.issues).toHaveLength(6)
expect(result.error?.issues).toHaveLength(7)
})
})

Expand Down Expand Up @@ -240,6 +241,7 @@ describe('Variable Schema Tests', () => {
lastUpdatedBy: {
id: 'user123',
name: 'John Doe'
// Missing profilePicture
}
},
values: [
Expand All @@ -255,7 +257,7 @@ describe('Variable Schema Tests', () => {
]
})
expect(result.success).toBe(false)
expect(result.error?.issues).toHaveLength(5)
expect(result.error?.issues).toHaveLength(6)
})
})

Expand Down

0 comments on commit 5345925

Please sign in to comment.