feat(me): inline profile editing in the Profile tab (P3b)

Wires existing updateMyProfile + discloseAffiliations into an editable
form (name, handle, phone, bio, skills, interests, willing-to,
affiliations). Affiliations re-disclosed only when changed so the COI
timestamp is not reset on every save. Added bio to the updateMyProfile
param type (schema + column already supported it). 521 tests; build
clean (UI not browser-tested from here).
This commit is contained in:
Moheeb Zara
2026-05-18 15:46:15 -07:00
parent 5a7283266c
commit ef210c9fe5
4 changed files with 146 additions and 1 deletions
+8
View File
@@ -11,6 +11,7 @@ import { SIGNUP_STATUS_LABEL, SESSION_STATUS_LABEL } from '@/lib/classes-logic'
import { RESERVATION_STATUS_LABEL } from '@/lib/equipment-logic'
import { presenceStatus } from '@/lib/presence-logic'
import { DuesCard } from '@/components/billing/dues-card'
import { ProfileForm, type ProfileInitial } from './profile-form'
const STATUS_VARIANT: Record<CertStatus, 'default' | 'outline'> = {
active: 'default',
@@ -53,6 +54,7 @@ export type HeldPermission = { code: string; label: string }
export type Billing = { status: string | null; currentPeriodEnd: string | null; hasCustomer: boolean } | null
type Props = {
profile: ProfileInitial
grants: Grant[]
held: HeldPermission[]
billing: Billing
@@ -66,6 +68,7 @@ type Props = {
const sectionH = 'font-mono text-[10px] uppercase tracking-widest text-muted-foreground mb-3'
export function MePortalClient({
profile,
grants,
held,
billing,
@@ -94,6 +97,11 @@ export function MePortalClient({
</TabsList>
<TabsContent value="profile" className="space-y-8">
<section>
<h2 className={sectionH}>Profile</h2>
<ProfileForm initial={profile} />
</section>
<section>
<h2 className={sectionH}>My permissions</h2>
{held.length === 0 ? (
+15 -1
View File
@@ -24,12 +24,25 @@ export default async function MePage() {
const { data: member } = await supabase
.from('space_members')
.select('id, space_id, role, display_name')
.select(
'id, space_id, role, display_name, handle, phone, bio, skills, interests, willing_to, affiliations',
)
.eq('user_id', user.id)
.in('status', ['current', 'unverified', 'late'])
.maybeSingle()
if (!member) redirect('/signup')
const profile = {
display_name: (member.display_name as string | null) ?? '',
handle: (member.handle as string | null) ?? '',
phone: (member.phone as string | null) ?? '',
bio: (member.bio as string | null) ?? '',
skills: (member.skills as string[] | null) ?? [],
interests: (member.interests as string[] | null) ?? [],
willing_to: (member.willing_to as string[] | null) ?? [],
affiliations: (member.affiliations as string[] | null) ?? [],
}
const { data: grantsRaw } = await supabase
.from('member_certifications')
.select(
@@ -91,6 +104,7 @@ export default async function MePage() {
</PageHeader>
<MePortalClient
profile={profile}
grants={grants}
held={held}
billing={billing}
+122
View File
@@ -0,0 +1,122 @@
'use client'
import { useState } from 'react'
import { useRouter } from 'next/navigation'
import { toast } from 'sonner'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Textarea } from '@/components/ui/textarea'
import { updateMyProfile, discloseAffiliations } from '@/lib/actions'
export type ProfileInitial = {
display_name: string
handle: string
phone: string
bio: string
skills: string[]
interests: string[]
willing_to: string[]
affiliations: string[]
}
const toList = (s: string): string[] =>
s.split(',').map(x => x.trim()).filter(Boolean)
const sameList = (a: string[], b: string[]) =>
a.length === b.length && a.every((x, i) => x === b[i])
export function ProfileForm({ initial }: { initial: ProfileInitial }) {
const router = useRouter()
const [busy, setBusy] = useState(false)
const [displayName, setDisplayName] = useState(initial.display_name)
const [handle, setHandle] = useState(initial.handle)
const [phone, setPhone] = useState(initial.phone)
const [bio, setBio] = useState(initial.bio)
const [skills, setSkills] = useState(initial.skills.join(', '))
const [interests, setInterests] = useState(initial.interests.join(', '))
const [willingTo, setWillingTo] = useState(initial.willing_to.join(', '))
const [affiliations, setAffiliations] = useState(initial.affiliations.join(', '))
async function save() {
if (!displayName.trim()) return toast.error('Display name is required.')
setBusy(true)
const res = await updateMyProfile({
display_name: displayName.trim(),
handle: handle.trim() || null,
phone: phone.trim() || null,
bio: bio.trim() || null,
skills: toList(skills),
interests: toList(interests),
willing_to: toList(willingTo),
})
if ('error' in res && res.error) {
setBusy(false)
return toast.error(res.error)
}
// Only re-disclose affiliations when they actually changed, so the
// conflict-of-interest disclosure timestamp is not reset on every save.
const nextAffiliations = toList(affiliations)
if (!sameList(nextAffiliations, initial.affiliations)) {
const aff = await discloseAffiliations({ affiliations: nextAffiliations })
if ('error' in aff && aff.error) {
setBusy(false)
return toast.error(aff.error)
}
}
setBusy(false)
toast.success('Profile saved.')
router.refresh()
}
return (
<div className="bg-card rounded border border-border p-4 space-y-4">
<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-1.5">
<Label htmlFor="pf-name">Display name</Label>
<Input id="pf-name" value={displayName} onChange={e => setDisplayName(e.target.value)} maxLength={100} />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-handle">Handle</Label>
<Input id="pf-handle" value={handle} onChange={e => setHandle(e.target.value)} maxLength={50} placeholder="optional" />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-phone">Phone</Label>
<Input id="pf-phone" value={phone} onChange={e => setPhone(e.target.value)} maxLength={20} placeholder="optional" />
</div>
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-bio">Bio</Label>
<Textarea id="pf-bio" value={bio} onChange={e => setBio(e.target.value)} maxLength={2000} rows={3} placeholder="optional" />
</div>
<div className="grid gap-4 sm:grid-cols-2">
<div className="space-y-1.5">
<Label htmlFor="pf-skills">Skills</Label>
<Input id="pf-skills" value={skills} onChange={e => setSkills(e.target.value)} placeholder="comma, separated" />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-interests">Interests</Label>
<Input id="pf-interests" value={interests} onChange={e => setInterests(e.target.value)} placeholder="comma, separated" />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-willing">Willing to</Label>
<Input id="pf-willing" value={willingTo} onChange={e => setWillingTo(e.target.value)} placeholder="comma, separated" />
</div>
<div className="space-y-1.5">
<Label htmlFor="pf-aff">Affiliations (conflict-of-interest)</Label>
<Input id="pf-aff" value={affiliations} onChange={e => setAffiliations(e.target.value)} placeholder="comma, separated" />
</div>
</div>
<div className="flex justify-end">
<Button size="sm" disabled={busy} onClick={save}>
{busy ? 'Saving…' : 'Save profile'}
</Button>
</div>
</div>
)
}
+1
View File
@@ -166,6 +166,7 @@ export async function updateMyProfile(updates: {
display_name?: string
handle?: string | null
phone?: string | null
bio?: string | null
skills?: string[]
interests?: string[]
willing_to?: string[]