chore: updated frontend code to build
parent
18e4b8d116
commit
31c54be970
|
@ -35,11 +35,6 @@ interface UsersResponse {
|
||||||
data: User[]
|
data: User[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserResponse {
|
|
||||||
success: boolean
|
|
||||||
user: User
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CreateUserRequest {
|
interface CreateUserRequest {
|
||||||
email: string
|
email: string
|
||||||
password: string
|
password: string
|
||||||
|
@ -51,21 +46,11 @@ interface UpdateUserRequest {
|
||||||
password?: string
|
password?: string
|
||||||
roles: string[]
|
roles: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DeleteUserResponse {
|
|
||||||
success: boolean
|
|
||||||
message: string
|
|
||||||
}
|
|
||||||
|
|
||||||
interface UpdateUserResponse {
|
|
||||||
success: boolean
|
|
||||||
message: string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Roles disponíveis no sistema
|
// Roles disponíveis no sistema
|
||||||
const AVAILABLE_ROLES = [
|
const AVAILABLE_ROLES = [
|
||||||
{ id: "admin", label: "Administrador", description: "Acesso total ao sistema" },
|
{ id: "admin", label: "Administrador", description: "Acesso total ao sistema" },
|
||||||
{ id: "user", label: "Usuário", description: "Acesso parcial, não pode gerenciar usuários" },
|
{ id: "user", label: "Usuário", description: "Acesso parcial, não pode gerenciar usuários" },
|
||||||
]
|
]
|
||||||
|
|
||||||
export default function UserManagement() {
|
export default function UserManagement() {
|
||||||
|
@ -120,7 +105,8 @@ export default function UserManagement() {
|
||||||
const errorData = await response.json()
|
const errorData = await response.json()
|
||||||
setError(errorData.message || "Erro ao buscar usuários")
|
setError(errorData.message || "Erro ao buscar usuários")
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err: unknown) {
|
||||||
|
console.log(err)
|
||||||
setError("Erro de conexão com o servidor")
|
setError("Erro de conexão com o servidor")
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
|
@ -144,8 +130,7 @@ export default function UserManagement() {
|
||||||
body: JSON.stringify(createForm),
|
body: JSON.stringify(createForm),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const result = await response.json()
|
|
||||||
setSuccess("Usuário criado com sucesso!")
|
setSuccess("Usuário criado com sucesso!")
|
||||||
setCreateForm({ email: "", password: "", roles: [] })
|
setCreateForm({ email: "", password: "", roles: [] })
|
||||||
setIsCreateDialogOpen(false)
|
setIsCreateDialogOpen(false)
|
||||||
|
@ -154,7 +139,8 @@ export default function UserManagement() {
|
||||||
const errorData = await response.json()
|
const errorData = await response.json()
|
||||||
setError(errorData.message || "Erro ao criar usuário")
|
setError(errorData.message || "Erro ao criar usuário")
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err:unknown) {
|
||||||
|
console.log(err)
|
||||||
setError("Erro de conexão com o servidor")
|
setError("Erro de conexão com o servidor")
|
||||||
} finally {
|
} finally {
|
||||||
setIsCreating(false)
|
setIsCreating(false)
|
||||||
|
@ -188,8 +174,7 @@ export default function UserManagement() {
|
||||||
body: JSON.stringify(updateData),
|
body: JSON.stringify(updateData),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const result: UpdateUserResponse = await response.json()
|
|
||||||
setSuccess("Usuário atualizado com sucesso!")
|
setSuccess("Usuário atualizado com sucesso!")
|
||||||
setEditingUser(null)
|
setEditingUser(null)
|
||||||
setEditForm({ email: "", password: "", roles: [] })
|
setEditForm({ email: "", password: "", roles: [] })
|
||||||
|
@ -199,6 +184,7 @@ export default function UserManagement() {
|
||||||
setError(errorData.message || "Erro ao atualizar usuário")
|
setError(errorData.message || "Erro ao atualizar usuário")
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
setError("Erro de conexão com o servidor")
|
setError("Erro de conexão com o servidor")
|
||||||
} finally {
|
} finally {
|
||||||
setIsUpdating(false)
|
setIsUpdating(false)
|
||||||
|
@ -220,15 +206,15 @@ export default function UserManagement() {
|
||||||
headers: getAuthHeaders(),
|
headers: getAuthHeaders(),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const result: DeleteUserResponse = await response.json()
|
|
||||||
setSuccess("Usuário excluído com sucesso!")
|
setSuccess("Usuário excluído com sucesso!")
|
||||||
await fetchUsers()
|
await fetchUsers()
|
||||||
} else {
|
} else {
|
||||||
const errorData = await response.json()
|
const errorData = await response.json()
|
||||||
setError(errorData.message || "Erro ao excluir usuário")
|
setError(errorData.message || "Erro ao excluir usuário")
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err:unknown) {
|
||||||
|
console.log(err)
|
||||||
setError("Erro de conexão com o servidor")
|
setError("Erro de conexão com o servidor")
|
||||||
} finally {
|
} finally {
|
||||||
setIsDeleting(null)
|
setIsDeleting(null)
|
||||||
|
|
Loading…
Reference in New Issue