diff --git a/src/app/admin/dashboard/_components/addRole.tsx b/src/app/admin/dashboard/_components/addRole.tsx index d49b8b9..ea62631 100644 --- a/src/app/admin/dashboard/_components/addRole.tsx +++ b/src/app/admin/dashboard/_components/addRole.tsx @@ -1,18 +1,44 @@ import TextInput from '@/app/(user)/register/_components/textInput'; import { Button } from '@/components/ui/button'; +import { useAuth } from '@/contexts/auth'; import { UserPlus } from 'lucide-react'; - +import { useState } from 'react'; +import toast from 'react-hot-toast'; +import { useAddStaff } from '../api/user'; export default function AddRole() { + const [phone, setPhone] = useState(''); + const { token } = useAuth(); + const { mutateAsync: addStaff } = useAddStaff(token?.accessToken || ''); + const { user } = useAuth(); + + function onAddStaff() { + if (phone == user?.phone) { + toast.error('You cannot add yourself as a staff member', { + duration: 5000, + }); + return; + } + const resp = addStaff({ phone }); + toast.promise(resp, { + loading: 'Adding staff', + success: 'Adding staff successful', + error: 'No user found with that phone number', + }); + } + return (
setPhone(e.target.value)} />