Merge pull request 'fix/avatar-endpoint' (#76) from fix/avatar-endpoint into develop
Reviewed-on: #76
This commit is contained in:
commit
ef133fc9c0
@ -10,10 +10,11 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Avatar, AvatarFallback } from '@/components/ui/avatar'
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
|
||||
import { User, LogOut, Calendar, FileText, MessageCircle, UserCog, Home, Clock, FolderOpen, ChevronLeft, ChevronRight, MapPin, Stethoscope } from 'lucide-react'
|
||||
import { SimpleThemeToggle } from '@/components/ui/simple-theme-toggle'
|
||||
import { UploadAvatar } from '@/components/ui/upload-avatar'
|
||||
import { useAvatarUrl } from '@/hooks/useAvatarUrl'
|
||||
import Link from 'next/link'
|
||||
import ProtectedRoute from '@/components/shared/ProtectedRoute'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
@ -91,6 +92,9 @@ export default function PacientePage() {
|
||||
})
|
||||
const [patientId, setPatientId] = useState<string | null>(null)
|
||||
|
||||
// Hook para carregar automaticamente o avatar do paciente
|
||||
const { avatarUrl: retrievedAvatarUrl } = useAvatarUrl(patientId)
|
||||
|
||||
// Load authoritative patient row for the logged-in user (prefer user_id lookup)
|
||||
useEffect(() => {
|
||||
let mounted = true
|
||||
@ -236,6 +240,16 @@ export default function PacientePage() {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [user?.id, user?.email])
|
||||
|
||||
// Sincroniza a URL do avatar recuperada com o profileData
|
||||
useEffect(() => {
|
||||
if (retrievedAvatarUrl) {
|
||||
setProfileData((prev: any) => ({
|
||||
...prev,
|
||||
foto_url: retrievedAvatarUrl
|
||||
}))
|
||||
}
|
||||
}, [retrievedAvatarUrl])
|
||||
|
||||
const handleProfileChange = (field: string, value: string) => {
|
||||
setProfileData((prev: any) => ({ ...prev, [field]: value }))
|
||||
}
|
||||
@ -1736,6 +1750,7 @@ export default function PacientePage() {
|
||||
) : (
|
||||
<div className="flex flex-col items-center gap-3 sm:gap-4">
|
||||
<Avatar className="h-20 w-20 sm:h-24 sm:w-24 md:h-28 md:w-28">
|
||||
<AvatarImage src={profileData.foto_url} alt={profileData.nome || 'Avatar'} />
|
||||
<AvatarFallback className="bg-primary text-primary-foreground text-lg sm:text-xl md:text-2xl font-bold">
|
||||
{profileData.nome?.split(' ').map((n: string) => n[0]).join('').toUpperCase().slice(0, 2) || 'PC'}
|
||||
</AvatarFallback>
|
||||
@ -1763,6 +1778,7 @@ export default function PacientePage() {
|
||||
<header className="sticky top-0 z-40 bg-card shadow-md rounded-lg border border-border p-3 sm:p-4 md:p-4 mb-4 sm:mb-6 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 sm:gap-4">
|
||||
<div className="flex items-center gap-2 sm:gap-4">
|
||||
<Avatar className="h-10 w-10 sm:h-12 sm:w-12 md:h-12 md:w-12">
|
||||
<AvatarImage src={profileData.foto_url} alt={profileData.nome || 'Avatar'} />
|
||||
<AvatarFallback className="bg-primary text-white font-bold text-sm sm:text-base">{profileData.nome?.charAt(0) || 'P'}</AvatarFallback>
|
||||
</Avatar>
|
||||
<div className="flex flex-col min-w-0">
|
||||
|
||||
@ -2747,35 +2747,6 @@ const ProfissionalPage = () => {
|
||||
{smsSending ? 'Enviando...' : 'Enviar SMS'}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Respostas do paciente */}
|
||||
<div className="mt-6 border-t border-border pt-4">
|
||||
<div className="flex items-center justify-between mb-3 flex-wrap gap-2">
|
||||
<h3 className="text-base sm:text-lg font-semibold">Últimas respostas do paciente</h3>
|
||||
<div>
|
||||
<Button size="sm" variant="outline" onClick={() => void loadCommResponses()} disabled={!commPatientId || commResponsesLoading} className="text-xs sm:text-sm">
|
||||
{commResponsesLoading ? 'Atualizando...' : 'Atualizar respostas'}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{commResponsesLoading ? (
|
||||
<div className="text-xs sm:text-sm text-muted-foreground">Carregando respostas...</div>
|
||||
) : commResponsesError ? (
|
||||
<div className="text-xs sm:text-sm text-red-500">{commResponsesError}</div>
|
||||
) : (commResponses && commResponses.length) ? (
|
||||
<div className="space-y-2">
|
||||
{commResponses.map((m:any) => (
|
||||
<div key={m.id} className="p-3 rounded border border-border bg-muted/10">
|
||||
<div className="text-xs text-muted-foreground">{m.created_at ? new Date(m.created_at).toLocaleString() : ''}</div>
|
||||
<div className="mt-1 whitespace-pre-wrap text-xs sm:text-sm">{m.body ?? m.content ?? m.message ?? '-'}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="text-xs sm:text-sm text-muted-foreground">Nenhuma resposta encontrada para o paciente selecionado.</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user