mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
Merge pull request #416 from jey-exp/enhancement/toast
Added toast notifications
This commit is contained in:
commit
4b89cca307
7 changed files with 24 additions and 7 deletions
|
|
@ -42,21 +42,25 @@ function OrgAccess() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteInvite(invite: any) {
|
async function deleteInvite(invite: any) {
|
||||||
|
const toastId = toast.loading("Deleting...")
|
||||||
let res = await deleteInviteCode(org.id, invite.invite_code_uuid, access_token)
|
let res = await deleteInviteCode(org.id, invite.invite_code_uuid, access_token)
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
mutate(`${getAPIUrl()}orgs/${org.id}/invites`)
|
mutate(`${getAPIUrl()}orgs/${org.id}/invites`)
|
||||||
|
toast.success("Deleted invite code", {id:toastId})
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error ' + res.status + ': ' + res.data.detail)
|
toast.error('Error deleting', {id:toastId})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function changeJoinMethod(method: 'open' | 'inviteOnly') {
|
async function changeJoinMethod(method: 'open' | 'inviteOnly') {
|
||||||
|
const toastId = toast.loading("Changing join method...")
|
||||||
let res = await changeSignupMechanism(org.id, method, access_token)
|
let res = await changeSignupMechanism(org.id, method, access_token)
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
router.refresh()
|
router.refresh()
|
||||||
mutate(`${getAPIUrl()}orgs/slug/${org?.slug}`)
|
mutate(`${getAPIUrl()}orgs/slug/${org?.slug}`)
|
||||||
|
toast.success(`Changed join method to ${method}`, {id:toastId})
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error ' + res.status + ': ' + res.data.detail)
|
toast.error('Error changing join method', {id:toastId})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,14 @@ function OrgUserGroups() {
|
||||||
)
|
)
|
||||||
|
|
||||||
const deleteUserGroupUI = async (usergroup_id: any) => {
|
const deleteUserGroupUI = async (usergroup_id: any) => {
|
||||||
|
const toastId = toast.loading("Deleting...");
|
||||||
const res = await deleteUserGroup(usergroup_id, access_token)
|
const res = await deleteUserGroup(usergroup_id, access_token)
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
mutate(`${getAPIUrl()}usergroups/org/${org.id}`)
|
mutate(`${getAPIUrl()}usergroups/org/${org.id}`)
|
||||||
|
toast.success("Deleted usergroup", {id:toastId})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
toast.error('Error ' + res.status + ': ' + res.data.detail)
|
toast.error('Error deleting usergroup', {id:toastId})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,13 @@ function OrgUsers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRemoveUser = async (user_id: any) => {
|
const handleRemoveUser = async (user_id: any) => {
|
||||||
|
const toastId = toast.loading("Removing...");
|
||||||
const res = await removeUserFromOrg(org.id, user_id,access_token)
|
const res = await removeUserFromOrg(org.id, user_id,access_token)
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
await mutate(`${getAPIUrl()}orgs/${org.id}/users`)
|
await mutate(`${getAPIUrl()}orgs/${org.id}/users`)
|
||||||
|
toast.success("Removed user from org", {id:toastId});
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error ' + res.status + ': ' + res.data.detail)
|
toast.error('Error removing user', {id:toastId});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,15 @@ function OrgUsersAdd() {
|
||||||
const [selectedInviteCode, setSelectedInviteCode] = React.useState('');
|
const [selectedInviteCode, setSelectedInviteCode] = React.useState('');
|
||||||
|
|
||||||
async function sendInvites() {
|
async function sendInvites() {
|
||||||
|
const toastId = toast.loading("Sending invite...")
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
let res = await inviteBatchUsers(org.id, invitedUsers, selectedInviteCode,access_token)
|
let res = await inviteBatchUsers(org.id, invitedUsers, selectedInviteCode,access_token)
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
mutate(`${getAPIUrl()}orgs/${org?.id}/invites/users`)
|
mutate(`${getAPIUrl()}orgs/${org?.id}/invites/users`)
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
|
toast.success("Invite sent", {id:toastId})
|
||||||
} else {
|
} else {
|
||||||
toast.error('Error ' + res.status + ': ' + res.data.detail)
|
toast.error('Error sending invite', {id:toastId})
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { mutate } from 'swr'
|
||||||
import { getAPIUrl } from '@services/config/config'
|
import { getAPIUrl } from '@services/config/config'
|
||||||
import { useLHSession } from '@components/Contexts/LHSessionContext'
|
import { useLHSession } from '@components/Contexts/LHSessionContext'
|
||||||
import { useFormik } from 'formik'
|
import { useFormik } from 'formik'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
|
||||||
type AddUserGroupProps = {
|
type AddUserGroupProps = {
|
||||||
setCreateUserGroupModal: any
|
setCreateUserGroupModal: any
|
||||||
|
|
@ -40,15 +41,17 @@ function AddUserGroup(props: AddUserGroupProps) {
|
||||||
},
|
},
|
||||||
validate,
|
validate,
|
||||||
onSubmit: async (values) => {
|
onSubmit: async (values) => {
|
||||||
|
const toastID = toast.loading("Creating...")
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
const res = await createUserGroup(values, access_token)
|
const res = await createUserGroup(values, access_token)
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
mutate(`${getAPIUrl()}usergroups/org/${org.id}`)
|
mutate(`${getAPIUrl()}usergroups/org/${org.id}`)
|
||||||
props.setCreateUserGroupModal(false)
|
props.setCreateUserGroupModal(false)
|
||||||
|
toast.success("Created new usergroup", {id:toastID})
|
||||||
} else {
|
} else {
|
||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
|
toast.error("Couldn't create new usergroup", {id:toastID})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { FormMessage } from '@radix-ui/react-form'
|
||||||
import { getAPIUrl } from '@services/config/config'
|
import { getAPIUrl } from '@services/config/config'
|
||||||
import { updateUserRole } from '@services/organizations/orgs'
|
import { updateUserRole } from '@services/organizations/orgs'
|
||||||
import React, { useEffect } from 'react'
|
import React, { useEffect } from 'react'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
import { BarLoader } from 'react-spinners'
|
import { BarLoader } from 'react-spinners'
|
||||||
import { mutate } from 'swr'
|
import { mutate } from 'swr'
|
||||||
|
|
||||||
|
|
@ -40,13 +41,15 @@ function RolesUpdate(props: Props) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
const res = await updateUserRole(org.id, props.user.user.id, assignedRole,access_token)
|
const res = await updateUserRole(org.id, props.user.user.id, assignedRole,access_token)
|
||||||
|
const toastId = toast.loading("Updating role...")
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
await mutate(`${getAPIUrl()}orgs/${org.id}/users`)
|
await mutate(`${getAPIUrl()}orgs/${org.id}/users`)
|
||||||
props.setRolesModal(false)
|
props.setRolesModal(false)
|
||||||
|
toast.success("Updated role", {id:toastId})
|
||||||
} else {
|
} else {
|
||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
setError('Error ' + res.status + ': ' + res.data.detail)
|
setError('Error ' + res.status + ': ' + res.data.detail)
|
||||||
|
toast.error("Error while updating role", {id:toastId})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
import { getAPIUrl } from '../config/config'
|
import { getAPIUrl } from '../config/config'
|
||||||
import {
|
import {
|
||||||
RequestBodyWithAuthHeader,
|
RequestBodyWithAuthHeader,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue