From a128fb8b5d002fc19512e8fb17a6b9ea1f4c95e0 Mon Sep 17 00:00:00 2001 From: Jeroen Branje Date: Wed, 31 Jan 2024 13:30:53 +0100 Subject: [PATCH] feat: add toast to delete user button Signed-off-by: Jeroen Branje --- .../modules/Users/Users.actions.ts | 5 ++++- apps/envited.ascs.digital/modules/Users/Users.tsx | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/apps/envited.ascs.digital/modules/Users/Users.actions.ts b/apps/envited.ascs.digital/modules/Users/Users.actions.ts index de593afb..00e8440b 100644 --- a/apps/envited.ascs.digital/modules/Users/Users.actions.ts +++ b/apps/envited.ascs.digital/modules/Users/Users.actions.ts @@ -12,6 +12,9 @@ export async function deleteUser(id: string) { revalidatePath('/dashboard/users') } catch (e) { console.log('error', e) - throw error() + + return { + error: 'Something went wrong', + } } } diff --git a/apps/envited.ascs.digital/modules/Users/Users.tsx b/apps/envited.ascs.digital/modules/Users/Users.tsx index be40a331..0f6dd3a1 100644 --- a/apps/envited.ascs.digital/modules/Users/Users.tsx +++ b/apps/envited.ascs.digital/modules/Users/Users.tsx @@ -2,10 +2,11 @@ import { Card, Heading, Table, TableBody, TableCell, TableHeader, TableRow } from '@envited-marketplace/design-system' import { TrashIcon } from '@heroicons/react/24/outline' -import { map } from 'ramda' +import { has, map } from 'ramda' import React, { FC } from 'react' import { useTranslation } from '../../common/i18n' +import { useNotification } from '../../common/notifications' import { User } from '../../common/types/types' import { deleteUser } from './Users.actions' @@ -14,8 +15,17 @@ interface UsersProps { } export const Users: FC = ({ users }) => { const { t } = useTranslation('Users') + const { error, success } = useNotification() - const deleteUserWithId = (id: string) => deleteUser.bind(null, id) + const deleteUserWithId = (id: string) => async () => { + const result = await deleteUser(id) + + if (has('error')(result)) { + return error('Something went wrong') + } + + success('User is deactivated') + } return (