Skip to content

Commit

Permalink
[SOA-43] User verified flag (#45)
Browse files Browse the repository at this point in the history
* feat 🎸 (be): add verified flag to user

* styles 💅 : add conditional verified badge to UI
  • Loading branch information
mariadriana-deemaze authored Nov 28, 2024
1 parent d18dff2 commit 9a398d6
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/interfaces/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface UserResponse extends BaseEntity {
fullname: string
username: string
email: string
verified: boolean
attachments: {
cover: AttachmentResponse | null
avatar: AttachmentResponse | null
Expand Down
3 changes: 3 additions & 0 deletions app/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export default class User extends compose(BaseModel, AuthFinder, Notifiable('use
@column()
declare email: string

@column()
declare verified: boolean

@column()
role: AccountRole = AccountRole.USER

Expand Down
1 change: 1 addition & 0 deletions app/services/user_notification_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class UserNotificationService {
surname: null,
fullname: 'Moderation team',
email: '[email protected]',
verified: true,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
role: AccountRole.ADMIN,
Expand Down
1 change: 1 addition & 0 deletions app/services/user_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export class UserService {
const resource: UserResponse = {
id: data.id,
role: data.role,
verified: data.verified,
name: data.name,
surname: data.surname,
fullname: data.fullName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { BaseSchema } from '@adonisjs/lucid/schema'

export default class extends BaseSchema {
protected tableName = 'users'

async up() {
this.schema.alterTable(this.tableName, (table) => {
table.boolean('verified').defaultTo(false)
})
}

async down() {
this.schema.alterTable(this.tableName, (table) => {
table.dropColumn('verified')
})
}
}
12 changes: 9 additions & 3 deletions inertia/components/posts/post_card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Trash2,
Flag,
Pin,
BadgeCheck,
} from 'lucide-react'
import { Button } from '@/components/ui/button'
import {
Expand Down Expand Up @@ -493,9 +494,14 @@ export default function PostCard({
<div className="flex flex-row gap-3">
<UserAvatar user={post.user} className="h-8 w-8" />
<div className="flex flex-col gap-1">
<p className="text-xs text-gray-600 text-ellipsis truncate max-w-40 md:max-w-screen-lg">
@{post.user.username}
</p>
<div className="flex flex-row gap-2 items-center">
<p className="text-xs text-gray-600 text-ellipsis truncate max-w-40 md:max-w-screen-lg">
@{post.user.username}
</p>
{post.user.verified && (
<BadgeCheck size={14} className="fill-blue-500 stroke-white" />
)}
</div>
<span className="flex text-xs text-gray-400 gap-1 items-center">
<Clock size={10} />
{formatDistanceToNow(new Date(post.createdAt))} ago
Expand Down
11 changes: 7 additions & 4 deletions inertia/pages/users/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Card, CardContent } from '@/components/ui/card'
import { InferPageProps } from '@adonisjs/inertia/types'
import { lightFormat } from 'date-fns'
import { Head } from '@inertiajs/react'
import { CalendarHeart, FilePen } from 'lucide-react'
import { BadgeCheck, CalendarHeart, FilePen } from 'lucide-react'
import { CreatePost } from '@/components/posts/create'
import { UserResponse } from '#interfaces/user'
import { route } from '@izzyjs/route/client'
Expand All @@ -23,9 +23,12 @@ function UserCard({ user, totalPosts }: { user: UserResponse; totalPosts: number
className="h-28 w-28 lg:h-20 lg:w-20 border-4 border-white shadow-lg"
/>
</div>
<div>
<h4 className="text-md">{user.name}</h4>
<p className="text-xs max-w-fit truncate text-ellipsis text-muted-foreground">
<div className="flex flex-col items-center">
<div className="flex flex-row gap-1 items-center justify-center">
<h4 className="text-md text-ellipsis truncate max-w-72 lg:max-w-40">{user.name}</h4>
{user.verified && <BadgeCheck size={16} className="fill-blue-500 stroke-white" />}
</div>
<p className="text-xs max-w-72 lg:max-w-40 truncate text-ellipsis text-muted-foreground">
@{user.username}
</p>
</div>
Expand Down

0 comments on commit 9a398d6

Please sign in to comment.