Skip to content

Commit

Permalink
update maj
Browse files Browse the repository at this point in the history
  • Loading branch information
carolineBda committed Sep 26, 2024
1 parent cc09eb8 commit 815ce43
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions targets/frontend/src/components/user/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ query getUsers {
`;

type Props = {
onDeleteUser: (userId: string, name: string) => Promise<boolean>;
onDeleteUser: (userId: string, userName: string) => Promise<boolean>;
refresh?: boolean;
};

Expand All @@ -47,8 +47,8 @@ export function UserList({ onDeleteUser }: Props) {
const { data, fetching, error } = result;
const users = data?.users || [];

function confirmDeleteUser(id: string, email: string) {
setSelectedUser({ email, id });
function confirmDeleteUser(id: string, email: string, userName:string) {
setSelectedUser({ email, id, userName });
open();
}

Expand All @@ -57,7 +57,7 @@ export function UserList({ onDeleteUser }: Props) {
return;
}
close();
const result = await onDeleteUser(selectedUser.id, selectedUser.name);
const result = await onDeleteUser(selectedUser.id, selectedUser.userName);
if (result) {
executeQuery({ requestPolicy: "network-only" });
}
Expand All @@ -78,7 +78,7 @@ export function UserList({ onDeleteUser }: Props) {
ariaLabel="Supprimer l'utilisateur"
>
<p>Etes vous sur de vouloir supprimer l’utilisateur</p>
<strong>{selectedUser?.email}</strong>
<strong>{selectedUser?.userName} ({selectedUser?.email})</strong>
<Stack direction="row" spacing={2} mt={4} justifyContent="end">
<Button variant="outlined" onClick={close}>
Annuler
Expand Down Expand Up @@ -117,7 +117,7 @@ export function UserList({ onDeleteUser }: Props) {
</TableCell>
<TableCell align="center">
<MenuButton variant="contained">
<MenuItem onClick={() => confirmDeleteUser(id, email)}>
<MenuItem onClick={() => confirmDeleteUser(id, email, name)}>
Supprimer
</MenuItem>
</MenuButton>
Expand Down
6 changes: 3 additions & 3 deletions targets/frontend/src/modules/authentification/deleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const deleteQuery = gql`
isDeleted: true
}
) {
name
id
}
}
`;

interface DeleteUserHasuraResult {
update_auth_users_by_pk: {
name: string;
id: string;
};
}

Expand All @@ -46,7 +46,7 @@ export const deleteUser = async (
.toPromise();

if (
deleteResult.data?.update_auth_users_by_pk.name !== userId ||
deleteResult.data?.update_auth_users_by_pk.id !== userId ||
deleteResult.error
) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion targets/frontend/src/pages/api/users/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function handler(
}

const userId = req.body.userId;
const userName = req.body.name;
const userName = req.body.userName;

if (!userId) {
res.status(400).json({ message: "Missing user id" });
Expand Down
5 changes: 2 additions & 3 deletions targets/frontend/src/pages/users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import { useRouter } from "next/router";
export function UserPage() {
const router = useRouter();

const onDeleteUser = async (userId: string, name: string) => {
const onDeleteUser = async (userId: string, userName: string) => {
const result = await fetch(`/api/users/delete`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ userId, name }),
body: JSON.stringify({ userId, userName }),
});

const resultJson = await result.json();
Expand All @@ -26,7 +26,6 @@ export function UserPage() {
}

alert("L'utilisateur a été supprimé avec succès");

return true;
};

Expand Down

0 comments on commit 815ce43

Please sign in to comment.