Added toast notifications

This commit is contained in:
JeyGR 2024-12-18 22:17:01 +05:30 committed by jey-exp
parent feebdfcfe9
commit ab86a3b871
8 changed files with 48 additions and 18 deletions

View file

@ -12,6 +12,7 @@ import { mutate } from 'swr'
import { getAPIUrl } from '@services/config/config'
import { useLHSession } from '@components/Contexts/LHSessionContext'
import { useFormik } from 'formik'
import toast from 'react-hot-toast'
type AddUserGroupProps = {
setCreateUserGroupModal: any
@ -40,15 +41,17 @@ function AddUserGroup(props: AddUserGroupProps) {
},
validate,
onSubmit: async (values) => {
const toastID = toast.loading("Creating...")
setIsSubmitting(true)
const res = await createUserGroup(values, access_token)
if (res.status == 200) {
setIsSubmitting(false)
mutate(`${getAPIUrl()}usergroups/org/${org.id}`)
props.setCreateUserGroupModal(false)
toast.success("Created new usergroup", {id:toastID})
} else {
setIsSubmitting(false)
toast.error("Couldn't create new usergroup", {id:toastID})
}
},
})

View file

@ -12,6 +12,7 @@ import { FormMessage } from '@radix-ui/react-form'
import { getAPIUrl } from '@services/config/config'
import { updateUserRole } from '@services/organizations/orgs'
import React, { useEffect } from 'react'
import toast from 'react-hot-toast'
import { BarLoader } from 'react-spinners'
import { mutate } from 'swr'
@ -44,9 +45,11 @@ function RolesUpdate(props: Props) {
if (res.status === 200) {
await mutate(`${getAPIUrl()}orgs/${org.id}/users`)
props.setRolesModal(false)
toast.success("Updated role")
} else {
setIsSubmitting(false)
setError('Error ' + res.status + ': ' + res.data.detail)
toast.error("Couldn't update now")
}
}