From ab86a3b8719eaf8772d60173d5e2b1bab22c0c23 Mon Sep 17 00:00:00 2001 From: JeyGR Date: Wed, 18 Dec 2024 22:17:01 +0530 Subject: [PATCH 1/5] Added toast notifications --- .../Pages/Users/OrgAccess/OrgAccess.tsx | 8 +++- .../Users/OrgUserGroups/OrgUserGroups.tsx | 4 +- .../Pages/Users/OrgUsers/OrgUsers.tsx | 4 +- .../Pages/Users/OrgUsersAdd/OrgUsersAdd.tsx | 4 +- .../Dash/OrgUserGroups/AddUserGroup.tsx | 5 ++- .../Modals/Dash/OrgUsers/RolesUpdate.tsx | 3 ++ apps/web/services/courses/collections.ts | 37 +++++++++++++------ apps/web/services/settings/password.ts | 1 + 8 files changed, 48 insertions(+), 18 deletions(-) diff --git a/apps/web/components/Dashboard/Pages/Users/OrgAccess/OrgAccess.tsx b/apps/web/components/Dashboard/Pages/Users/OrgAccess/OrgAccess.tsx index ae14fe86..8fa6ed25 100644 --- a/apps/web/components/Dashboard/Pages/Users/OrgAccess/OrgAccess.tsx +++ b/apps/web/components/Dashboard/Pages/Users/OrgAccess/OrgAccess.tsx @@ -42,21 +42,25 @@ function OrgAccess() { } async function deleteInvite(invite: any) { + const toastId = toast.loading("Deleting...") let res = await deleteInviteCode(org.id, invite.invite_code_uuid, access_token) if (res.status == 200) { mutate(`${getAPIUrl()}orgs/${org.id}/invites`) + toast.success("Deleted invite code", {id:toastId}) } else { - toast.error('Error ' + res.status + ': ' + res.data.detail) + toast.error('Error deleting', {id:toastId}) } } async function changeJoinMethod(method: 'open' | 'inviteOnly') { + const toastId = toast.loading("Changing join method...") let res = await changeSignupMechanism(org.id, method, access_token) if (res.status == 200) { router.refresh() mutate(`${getAPIUrl()}orgs/slug/${org?.slug}`) + toast.success(`Changed join method to ${method}`, {id:toastId}) } else { - toast.error('Error ' + res.status + ': ' + res.data.detail) + toast.error('Error changing join method', {id:toastId}) } } diff --git a/apps/web/components/Dashboard/Pages/Users/OrgUserGroups/OrgUserGroups.tsx b/apps/web/components/Dashboard/Pages/Users/OrgUserGroups/OrgUserGroups.tsx index ba586ada..8d134f9a 100644 --- a/apps/web/components/Dashboard/Pages/Users/OrgUserGroups/OrgUserGroups.tsx +++ b/apps/web/components/Dashboard/Pages/Users/OrgUserGroups/OrgUserGroups.tsx @@ -29,12 +29,14 @@ function OrgUserGroups() { ) const deleteUserGroupUI = async (usergroup_id: any) => { + const toastId = toast.loading("Deleting..."); const res = await deleteUserGroup(usergroup_id, access_token) if (res.status == 200) { mutate(`${getAPIUrl()}usergroups/org/${org.id}`) + toast.success("Deleted usergroup", {id:toastId}) } else { - toast.error('Error ' + res.status + ': ' + res.data.detail) + toast.error('Error deleting usergroup', {id:toastId}) } } diff --git a/apps/web/components/Dashboard/Pages/Users/OrgUsers/OrgUsers.tsx b/apps/web/components/Dashboard/Pages/Users/OrgUsers/OrgUsers.tsx index 7d5bee0b..32fb37f7 100644 --- a/apps/web/components/Dashboard/Pages/Users/OrgUsers/OrgUsers.tsx +++ b/apps/web/components/Dashboard/Pages/Users/OrgUsers/OrgUsers.tsx @@ -31,11 +31,13 @@ function OrgUsers() { } const handleRemoveUser = async (user_id: any) => { + const toastId = toast.loading("Removing..."); const res = await removeUserFromOrg(org.id, user_id,access_token) if (res.status === 200) { await mutate(`${getAPIUrl()}orgs/${org.id}/users`) + toast.success("Removed user from org", {id:toastId}); } else { - toast.error('Error ' + res.status + ': ' + res.data.detail) + toast.error('Error removing user', {id:toastId}); } } diff --git a/apps/web/components/Dashboard/Pages/Users/OrgUsersAdd/OrgUsersAdd.tsx b/apps/web/components/Dashboard/Pages/Users/OrgUsersAdd/OrgUsersAdd.tsx index 496d25d9..f18543df 100644 --- a/apps/web/components/Dashboard/Pages/Users/OrgUsersAdd/OrgUsersAdd.tsx +++ b/apps/web/components/Dashboard/Pages/Users/OrgUsersAdd/OrgUsersAdd.tsx @@ -20,13 +20,15 @@ function OrgUsersAdd() { const [selectedInviteCode, setSelectedInviteCode] = React.useState(''); async function sendInvites() { + const toastId = toast.loading("Sending invite...") setIsLoading(true) let res = await inviteBatchUsers(org.id, invitedUsers, selectedInviteCode,access_token) if (res.status == 200) { mutate(`${getAPIUrl()}orgs/${org?.id}/invites/users`) setIsLoading(false) + toast.success("Invite sent", {id:toastId}) } else { - toast.error('Error ' + res.status + ': ' + res.data.detail) + toast.error('Error sending invite', {id:toastId}) setIsLoading(false) } diff --git a/apps/web/components/Objects/Modals/Dash/OrgUserGroups/AddUserGroup.tsx b/apps/web/components/Objects/Modals/Dash/OrgUserGroups/AddUserGroup.tsx index 7389f50d..403796c0 100644 --- a/apps/web/components/Objects/Modals/Dash/OrgUserGroups/AddUserGroup.tsx +++ b/apps/web/components/Objects/Modals/Dash/OrgUserGroups/AddUserGroup.tsx @@ -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}) } }, }) diff --git a/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx b/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx index 9168a7a2..30ddf8b1 100644 --- a/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx +++ b/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx @@ -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") } } diff --git a/apps/web/services/courses/collections.ts b/apps/web/services/courses/collections.ts index fb67264a..8334c469 100644 --- a/apps/web/services/courses/collections.ts +++ b/apps/web/services/courses/collections.ts @@ -1,3 +1,4 @@ +import toast from 'react-hot-toast' import { getAPIUrl } from '../config/config' import { RequestBodyWithAuthHeader, @@ -13,22 +14,34 @@ export async function deleteCollection( collection_uuid: any, access_token: any ) { - const result: any = await fetch( - `${getAPIUrl()}collections/${collection_uuid}`, - RequestBodyWithAuthHeader('DELETE', null, null, access_token) - ) - const res = await errorHandling(result) - return res + const toastId = toast.loading("Deleting collection...") + try { + const result: any = await fetch( + `${getAPIUrl()}collections/${collection_uuid}`, + RequestBodyWithAuthHeader('DELETE', null, null, access_token) + ) + toast.success("Deleted colletion", {id:toastId}) + const res = await errorHandling(result) + return res + } catch (error) { + toast.error("Couldn't delete collection", {id:toastId}) + } } // Create a new collection export async function createCollection(collection: any, access_token: any) { - const result: any = await fetch( - `${getAPIUrl()}collections/`, - RequestBodyWithAuthHeader('POST', collection, null, access_token) - ) - const res = await errorHandling(result) - return res + const toastId = toast.loading("Creating...") + try { + const result: any = await fetch( + `${getAPIUrl()}collections/`, + RequestBodyWithAuthHeader('POST', collection, null, access_token) + ) + toast.success("New collection created", {id:toastId}) + const res = await errorHandling(result) + return res + } catch (error) { + toast.error("Couldn't create collection", {id:toastId}) + } } export async function getCollectionById( diff --git a/apps/web/services/settings/password.ts b/apps/web/services/settings/password.ts index e580a616..c8e533d0 100644 --- a/apps/web/services/settings/password.ts +++ b/apps/web/services/settings/password.ts @@ -4,6 +4,7 @@ import { errorHandling, getResponseMetadata, } from '@services/utils/ts/requests' +import toast from 'react-hot-toast' /* This file includes only POST, PUT, DELETE requests From 6e3d6cee396180489b845a0af6fa033156c71b3c Mon Sep 17 00:00:00 2001 From: JeyGR Date: Thu, 19 Dec 2024 11:15:07 +0530 Subject: [PATCH 2/5] Chore fix --- .../components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx b/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx index 30ddf8b1..e8bea627 100644 --- a/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx +++ b/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx @@ -41,15 +41,15 @@ function RolesUpdate(props: Props) { e.preventDefault() setIsSubmitting(true) const res = await updateUserRole(org.id, props.user.user.id, assignedRole,access_token) - + const toastId = toast.loading("Updating role...") if (res.status === 200) { await mutate(`${getAPIUrl()}orgs/${org.id}/users`) props.setRolesModal(false) - toast.success("Updated role") + toast.success("Updated role", {id:toastId}) } else { setIsSubmitting(false) setError('Error ' + res.status + ': ' + res.data.detail) - toast.error("Couldn't update now") + toast.error("Couldn't update now", {id:toastId}) } } From bb1ac403f16815fe69cceb0ab1d68d31cf908ff2 Mon Sep 17 00:00:00 2001 From: JeyGR Date: Thu, 19 Dec 2024 13:18:28 +0530 Subject: [PATCH 3/5] Fixing build issue-Passing PAT --- .../web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx b/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx index e8bea627..0c14a500 100644 --- a/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx +++ b/apps/web/components/Objects/Modals/Dash/OrgUsers/RolesUpdate.tsx @@ -49,7 +49,7 @@ function RolesUpdate(props: Props) { } else { setIsSubmitting(false) setError('Error ' + res.status + ': ' + res.data.detail) - toast.error("Couldn't update now", {id:toastId}) + toast.error("Error while updating role", {id:toastId}) } } From b751ade3d82d64836e89da9683914c069613e105 Mon Sep 17 00:00:00 2001 From: jey-exp Date: Thu, 6 Mar 2025 00:18:29 +0530 Subject: [PATCH 4/5] chore: fixed toast from services --- apps/web/services/courses/collections.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/web/services/courses/collections.ts b/apps/web/services/courses/collections.ts index 8334c469..16b21801 100644 --- a/apps/web/services/courses/collections.ts +++ b/apps/web/services/courses/collections.ts @@ -14,33 +14,33 @@ export async function deleteCollection( collection_uuid: any, access_token: any ) { - const toastId = toast.loading("Deleting collection...") + const = toast.loading("Deleting collection...") try { const result: any = await fetch( `${getAPIUrl()}collections/${collection_uuid}`, RequestBodyWithAuthHeader('DELETE', null, null, access_token) ) - toast.success("Deleted colletion", {id:toastId}) + toast.success("Deleted colletion", {id:}) const res = await errorHandling(result) return res } catch (error) { - toast.error("Couldn't delete collection", {id:toastId}) + toast.error("Couldn't delete collection", {id:}) } } // Create a new collection export async function createCollection(collection: any, access_token: any) { - const toastId = toast.loading("Creating...") + const = toast.loading("Creating...") try { const result: any = await fetch( `${getAPIUrl()}collections/`, RequestBodyWithAuthHeader('POST', collection, null, access_token) ) - toast.success("New collection created", {id:toastId}) + toast.success("New collection created", {id:}) const res = await errorHandling(result) return res } catch (error) { - toast.error("Couldn't create collection", {id:toastId}) + toast.error("Couldn't create collection", {id:}) } } From bc3a20e1f641a4bfa8b6b26e8edba2f5f3d7d4da Mon Sep 17 00:00:00 2001 From: jey-exp Date: Thu, 6 Mar 2025 00:41:44 +0530 Subject: [PATCH 5/5] chore fix --- apps/web/services/courses/collections.ts | 36 ++++++++---------------- apps/web/services/settings/password.ts | 1 - 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/apps/web/services/courses/collections.ts b/apps/web/services/courses/collections.ts index 16b21801..097a8deb 100644 --- a/apps/web/services/courses/collections.ts +++ b/apps/web/services/courses/collections.ts @@ -14,34 +14,22 @@ export async function deleteCollection( collection_uuid: any, access_token: any ) { - const = toast.loading("Deleting collection...") - try { - const result: any = await fetch( - `${getAPIUrl()}collections/${collection_uuid}`, - RequestBodyWithAuthHeader('DELETE', null, null, access_token) - ) - toast.success("Deleted colletion", {id:}) - const res = await errorHandling(result) - return res - } catch (error) { - toast.error("Couldn't delete collection", {id:}) - } + const result: any = await fetch( + `${getAPIUrl()}collections/${collection_uuid}`, + RequestBodyWithAuthHeader('DELETE', null, null, access_token) + ) + const res = await errorHandling(result) + return res } // Create a new collection export async function createCollection(collection: any, access_token: any) { - const = toast.loading("Creating...") - try { - const result: any = await fetch( - `${getAPIUrl()}collections/`, - RequestBodyWithAuthHeader('POST', collection, null, access_token) - ) - toast.success("New collection created", {id:}) - const res = await errorHandling(result) - return res - } catch (error) { - toast.error("Couldn't create collection", {id:}) - } + const result: any = await fetch( + `${getAPIUrl()}collections/`, + RequestBodyWithAuthHeader('POST', collection, null, access_token) + ) + const res = await errorHandling(result) + return res } export async function getCollectionById( diff --git a/apps/web/services/settings/password.ts b/apps/web/services/settings/password.ts index c8e533d0..e580a616 100644 --- a/apps/web/services/settings/password.ts +++ b/apps/web/services/settings/password.ts @@ -4,7 +4,6 @@ import { errorHandling, getResponseMetadata, } from '@services/utils/ts/requests' -import toast from 'react-hot-toast' /* This file includes only POST, PUT, DELETE requests