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:
@@ -48,6 +48,22 @@ app.get('/api/users/:id', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Atualizar Usuário
|
||||||
|
app.put('/api/users/:id', async (req, res) => {
|
||||||
|
const { name, bio } = req.body;
|
||||||
|
try {
|
||||||
|
await pool.query(
|
||||||
|
'UPDATE users SET name = ?, bio = ? WHERE id = ?',
|
||||||
|
[name, bio, req.params.id]
|
||||||
|
);
|
||||||
|
res.json({ message: 'User updated successfully' });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erro ao atualizar usuário:', error);
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// --- Rotas de Atendimentos ---
|
// --- Rotas de Atendimentos ---
|
||||||
|
|
||||||
// Listar Atendimentos (Dashboard)
|
// Listar Atendimentos (Dashboard)
|
||||||
|
|||||||
30
docker-compose.local.yml
Normal file
30
docker-compose.local.yml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
build: .
|
||||||
|
container_name: fasto-app-local
|
||||||
|
ports:
|
||||||
|
- "3001:3001"
|
||||||
|
environment:
|
||||||
|
- NODE_ENV=production
|
||||||
|
- PORT=3001
|
||||||
|
- DB_HOST=db
|
||||||
|
- DB_USER=${DB_USER:-root}
|
||||||
|
- DB_PASSWORD=${DB_PASSWORD:-root_password}
|
||||||
|
- DB_NAME=${DB_NAME:-agenciac_comia}
|
||||||
|
volumes:
|
||||||
|
- ./dist:/app/dist # Map local build to container
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: mysql:8.0
|
||||||
|
container_name: fasto-db-local
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root_password}
|
||||||
|
MYSQL_DATABASE: ${DB_NAME:-agenciac_comia}
|
||||||
|
volumes:
|
||||||
|
- ./agenciac_comia.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
|
- db_data_local:/var/lib/mysql
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data_local:
|
||||||
3280
package-lock.json
generated
Normal file
3280
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Camera, Save, Mail, User as UserIcon, Building, Shield, Loader2, CheckCircle2 } from 'lucide-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';
|
import { User, Tenant } from '../types';
|
||||||
|
|
||||||
export const UserProfile: React.FC = () => {
|
export const UserProfile: React.FC = () => {
|
||||||
@@ -38,18 +38,29 @@ export const UserProfile: React.FC = () => {
|
|||||||
fetchUserAndTenant();
|
fetchUserAndTenant();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
if (!user) return;
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setIsSuccess(false);
|
setIsSuccess(false);
|
||||||
|
|
||||||
// Simulate API call
|
try {
|
||||||
setTimeout(() => {
|
const success = await updateUser(user.id, { name, bio });
|
||||||
setIsLoading(false);
|
if (success) {
|
||||||
setIsSuccess(true);
|
setIsSuccess(true);
|
||||||
// In a real app, we would update the user context/store here
|
// Update local state
|
||||||
|
setUser({ ...user, name, bio });
|
||||||
setTimeout(() => setIsSuccess(false), 3000);
|
setTimeout(() => setIsSuccess(false), 3000);
|
||||||
}, 1500);
|
} 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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!user) return <div className="p-8 text-center text-slate-500">Carregando perfil...</div>;
|
if (!user) return <div className="p-8 text-center text-slate-500">Carregando perfil...</div>;
|
||||||
|
|||||||
@@ -57,6 +57,20 @@ export const getUserById = async (id: string): Promise<User | undefined> => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateUser = async (id: string, userData: { name: string, bio: string }): Promise<boolean> => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${API_URL}/users/${id}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(userData)
|
||||||
|
});
|
||||||
|
return response.ok;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("API Error (updateUser):", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const getAttendanceById = async (id: string): Promise<Attendance | undefined> => {
|
export const getAttendanceById = async (id: string): Promise<Attendance | undefined> => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}/attendances/${id}`);
|
const response = await fetch(`${API_URL}/attendances/${id}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user