feat: implement real profile save functionality
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m49s

This commit is contained in:
Cauê Faleiros
2026-02-26 10:42:01 -03:00
parent 6fb86b4806
commit 76b919d857
5 changed files with 3359 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
import React, { useState, useEffect } from 'react';
import { Camera, Save, Mail, User as UserIcon, Building, Shield, Loader2, CheckCircle2 } from 'lucide-react';
import { getUserById, getTenants } from '../services/dataService';
import { getUserById, getTenants, updateUser } from '../services/dataService';
import { User, Tenant } from '../types';
export const UserProfile: React.FC = () => {
@@ -38,18 +38,29 @@ export const UserProfile: React.FC = () => {
fetchUserAndTenant();
}, []);
const handleSubmit = (e: React.FormEvent) => {
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!user) return;
setIsLoading(true);
setIsSuccess(false);
// Simulate API call
setTimeout(() => {
try {
const success = await updateUser(user.id, { name, bio });
if (success) {
setIsSuccess(true);
// Update local state
setUser({ ...user, name, bio });
setTimeout(() => setIsSuccess(false), 3000);
} else {
alert('Erro ao salvar alterações no servidor.');
}
} catch (err) {
console.error("Submit failed:", err);
alert('Erro ao conectar ao servidor.');
} finally {
setIsLoading(false);
setIsSuccess(true);
// In a real app, we would update the user context/store here
setTimeout(() => setIsSuccess(false), 3000);
}, 1500);
}
};
if (!user) return <div className="p-8 text-center text-slate-500">Carregando perfil...</div>;