Skip to content

Commit

Permalink
feat: add toast to delete user button
Browse files Browse the repository at this point in the history
Signed-off-by: Jeroen Branje <[email protected]>
  • Loading branch information
jeroenbranje committed Jan 31, 2024
1 parent fec000b commit a128fb8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion apps/envited.ascs.digital/modules/Users/Users.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
}
}
14 changes: 12 additions & 2 deletions apps/envited.ascs.digital/modules/Users/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -14,8 +15,17 @@ interface UsersProps {
}
export const Users: FC<UsersProps> = ({ 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 (
<Card>
Expand Down

0 comments on commit a128fb8

Please sign in to comment.