feat: implement real profile save functionality
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m49s
All checks were successful
Build and Deploy / build-and-push (push) Successful in 1m49s
This commit is contained in:
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user