From dbde9c409bebbfa79f553e6bbcfd4ae0433b6fbe Mon Sep 17 00:00:00 2001 From: JasonMun7 Date: Sun, 2 Mar 2025 14:21:29 -0500 Subject: [PATCH 01/11] Completed Archive/Unarchive functionality --- backend/.env.example | 11 ----------- backend/src/API/coffeeChatAPI.ts | 32 ++++++++++++++++++++++++++++++++ backend/src/api.ts | 19 ++++++++++++++++++- backend/src/dao/CoffeeChatDao.ts | 28 ++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 12 deletions(-) delete mode 100644 backend/.env.example diff --git a/backend/.env.example b/backend/.env.example deleted file mode 100644 index bc3116d7d..000000000 --- a/backend/.env.example +++ /dev/null @@ -1,11 +0,0 @@ -FIREBASE_PRIVATE_KEY= -FIREBASE_PRIVATE_KEY_ID= -FIREBASE_DEV_PRIVATE_KEY= -FIREBASE_DEV_PRIVATE_KEY_ID= -IS_PROD=false -USE_PROD_DB=false -ALLOW_ADMIN=true -OAUTH_CLIENTID= -OAUTH_CLIENT_SECRET= -OAUTH_REFRESH_TOKEN= -GITHUB_VALIDATION_TOKEN= \ No newline at end of file diff --git a/backend/src/API/coffeeChatAPI.ts b/backend/src/API/coffeeChatAPI.ts index d651328f3..dd4791e8e 100644 --- a/backend/src/API/coffeeChatAPI.ts +++ b/backend/src/API/coffeeChatAPI.ts @@ -138,6 +138,38 @@ export const clearAllCoffeeChats = async (user: IdolMember): Promise => { await CoffeeChatDao.clearAllCoffeeChats(); }; +/** + * Archives all coffee chats by setting the isArchived field to true. + * @param user - The user making the request. + * @throws PermissionError if the user does not have permissions. + */ +export const archiveCoffeeChats = async (user: IdolMember): Promise => { + const canArchive = await PermissionsManager.isLeadOrAdmin(user); + if (!canArchive) { + throw new PermissionError( + `User with email ${user.email} does not have permission to archive coffee chats.` + ); + } + + await coffeeChatDao.archiveCoffeeChats(); +}; + +/** + * Unarchives all coffee chats by setting the isArchived field to false. + * @param user - The user making the request. + * @throws PermissionError if the user does not have permissions. + */ +export const unarchiveCoffeeChats = async (user: IdolMember): Promise => { + const canUnarchive = await PermissionsManager.isLeadOrAdmin(user); + if (!canUnarchive) { + throw new PermissionError( + `User with email ${user.email} does not have permission to unarchive coffee chats.` + ); + } + + await coffeeChatDao.unarchiveCoffeeChats(); +}; + /** * Gets the coffee chat bingo board */ diff --git a/backend/src/api.ts b/backend/src/api.ts index b23bd3ce2..3d9de4845 100644 --- a/backend/src/api.ts +++ b/backend/src/api.ts @@ -43,7 +43,9 @@ import { checkMemberMeetsCategory, runAutoChecker, notifyMemberCoffeeChat, - getCoffeeChatSuggestions + getCoffeeChatSuggestions, + archiveCoffeeChats, + unarchiveCoffeeChats } from './API/coffeeChatAPI'; import { allSignInForms, @@ -204,6 +206,11 @@ const loginCheckedPut = ( handler: (req: Request, user: IdolMember) => Promise> ) => router.put(path, loginCheckedHandler(handler)); +const loginCheckedPatch = ( + path: string, + handler: (req: Request, user: IdolMember) => Promise> +) => router.patch(path, loginCheckedHandler(handler)); + // Members router.get('/member', async (req, res) => { const type = req.query.type as string | undefined; @@ -341,6 +348,16 @@ loginCheckedPut('/coffee-chat', async (req, user) => ({ coffeeChat: await updateCoffeeChat(req.body, user) })); +loginCheckedPatch('/coffee-chat/archive', async (_, user) => { + await archiveCoffeeChats(user); + return { message: 'All coffee chats archived successfully.' }; +}); + +loginCheckedPatch('/coffee-chat/unarchive', async (_, user) => { + await unarchiveCoffeeChats(user); + return { message: 'All coffee chats unarchived successfully.' }; +}); + loginCheckedGet('/coffee-chat-bingo-board', async () => { const board = await getCoffeeChatBingoBoard(); return { board }; diff --git a/backend/src/dao/CoffeeChatDao.ts b/backend/src/dao/CoffeeChatDao.ts index cf6de09a7..330449cff 100644 --- a/backend/src/dao/CoffeeChatDao.ts +++ b/backend/src/dao/CoffeeChatDao.ts @@ -137,6 +137,34 @@ export default class CoffeeChatDao extends BaseDao { await deleteCollection(db, 'coffee-chats', 500); } + /** + * Archives all coffee chats by setting the isArchived field to true. + */ + async archiveCoffeeChats(): Promise { + const coffeeChats = await coffeeChatsCollection.where('isArchived', '==', false).get(); + const batch = db.batch(); + + coffeeChats.docs.forEach((doc) => { + batch.update(doc.ref, { isArchived: true }); + }); + + await batch.commit(); + } + + /** + * Unarchives all coffee chats by setting the isArchived field to false. + */ + async unarchiveCoffeeChats(): Promise { + const coffeeChats = await coffeeChatsCollection.where('isArchived', '==', true).get(); + const batch = db.batch(); + + coffeeChats.docs.forEach((doc) => { + batch.update(doc.ref, { isArchived: false }); + }); + + await batch.commit(); + } + /** * Gets the coffee chat bingo board */ From 671f28424c967a164591ee84219380066a5f39ef Mon Sep 17 00:00:00 2001 From: JasonMun7 Date: Sun, 2 Mar 2025 14:26:01 -0500 Subject: [PATCH 02/11] Added in patch --- frontend/.env.example | 4 -- frontend/src/API/APIWrapper.ts | 12 +++++ frontend/src/API/CoffeeChatAPI.ts | 26 +++++++++++ .../Admin/CoffeeChats/CoffeeChats.tsx | 44 +++++++++++++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) delete mode 100644 frontend/.env.example diff --git a/frontend/.env.example b/frontend/.env.example deleted file mode 100644 index 4ad13f73e..000000000 --- a/frontend/.env.example +++ /dev/null @@ -1,4 +0,0 @@ -NEXT_PUBLIC_USE_PROD_BACKEND_FOR_DEV=false -NEXT_PUBLIC_USE_PROD_DB=false -NEXT_PUBLIC_ALLOW_ADMIN=true -NEXT_PUBLIC_ALLOW_APPLICANT=false \ No newline at end of file diff --git a/frontend/src/API/APIWrapper.ts b/frontend/src/API/APIWrapper.ts index 00b3d35ba..26aeaaa1d 100644 --- a/frontend/src/API/APIWrapper.ts +++ b/frontend/src/API/APIWrapper.ts @@ -44,6 +44,18 @@ export default class APIWrapper { .then((resOrErr) => this.responseMiddleware(resOrErr)); } + public static async patch( + url: string, + body: unknown = {}, + config = {} + ): Promise { + const idToken = await getUserIDTokenNonNull(); + return axios + .patch(url, body, { headers: { ...config, 'auth-token': idToken } }) + .catch((err: AxiosError) => err) + .then((resOrErr) => this.responseMiddleware(resOrErr)); + } + private static responseMiddleware( resOrErr: AxiosResponse | AxiosError ): APIProcessedResponse { diff --git a/frontend/src/API/CoffeeChatAPI.ts b/frontend/src/API/CoffeeChatAPI.ts index 0c219216f..bd7ea5485 100644 --- a/frontend/src/API/CoffeeChatAPI.ts +++ b/frontend/src/API/CoffeeChatAPI.ts @@ -38,6 +38,32 @@ export default class CoffeeChatAPI { await APIWrapper.delete(`${backendURL}/coffee-chat/${uuid}`); } + public static async archiveCoffeeChats(): Promise { + return APIWrapper.patch(`${backendURL}/coffee-chat/archive`).then((res) => { + if (res.data.error) { + Emitters.generalError.emit({ + headerMsg: "Couldn't archive coffee chats", + contentMsg: `Error: ${res.data.error}` + }); + } else { + console.log(res.data.message); + } + }); + } + + public static async unarchiveCoffeeChats(): Promise { + return APIWrapper.patch(`${backendURL}/coffee-chat/unarchive`).then((res) => { + if (res.data.error) { + Emitters.generalError.emit({ + headerMsg: "Couldn't unarchive coffee chats", + contentMsg: `Error: ${res.data.error}` + }); + } else { + console.log(res.data.message); + } + }); + } + public static async getCoffeeChatBingoBoard(): Promise { const res = await APIWrapper.get(`${backendURL}/coffee-chat-bingo-board`).then( (res) => res.data diff --git a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx index 0e460d125..2a5a7b1db 100644 --- a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx +++ b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx @@ -62,6 +62,44 @@ const CoffeeChats: React.FC = () => { value: member.netid })); + const archiveAllCoffeeChats = async () => { + if ( + !confirm( + 'Are you sure you want to archive all coffee chats? This action cannot be undone! :)' + ) + ) { + return; + } + + try { + await CoffeeChatAPI.archiveCoffeeChats(); + alert('All coffee chats have been archived successfully.'); + setIsLoading(true); + } catch (error) { + console.error('Error archiving coffee chats:', error); + alert('Failed to archive coffee chats.'); + } + }; + + const unarchiveAllCoffeeChats = async () => { + if ( + !confirm( + 'Are you sure you want to unarchive all coffee chats? This action cannot be undone! :)' + ) + ) { + return; + } + + try { + await CoffeeChatAPI.unarchiveCoffeeChats(); + alert('All coffee chats have been archived successfully.'); + setIsLoading(true); + } catch (error) { + console.error('Error archiving coffee chats:', error); + alert('Failed to archive coffee chats.'); + } + }; + return (
@@ -124,6 +162,12 @@ const CoffeeChats: React.FC = () => { + +
Date: Sun, 2 Mar 2025 14:29:46 -0500 Subject: [PATCH 03/11] added back in the examples --- backend/.env.example | 11 +++++++++++ frontend/.env.example | 4 ++++ 2 files changed, 15 insertions(+) create mode 100644 backend/.env.example create mode 100644 frontend/.env.example diff --git a/backend/.env.example b/backend/.env.example new file mode 100644 index 000000000..bc3116d7d --- /dev/null +++ b/backend/.env.example @@ -0,0 +1,11 @@ +FIREBASE_PRIVATE_KEY= +FIREBASE_PRIVATE_KEY_ID= +FIREBASE_DEV_PRIVATE_KEY= +FIREBASE_DEV_PRIVATE_KEY_ID= +IS_PROD=false +USE_PROD_DB=false +ALLOW_ADMIN=true +OAUTH_CLIENTID= +OAUTH_CLIENT_SECRET= +OAUTH_REFRESH_TOKEN= +GITHUB_VALIDATION_TOKEN= \ No newline at end of file diff --git a/frontend/.env.example b/frontend/.env.example new file mode 100644 index 000000000..4ad13f73e --- /dev/null +++ b/frontend/.env.example @@ -0,0 +1,4 @@ +NEXT_PUBLIC_USE_PROD_BACKEND_FOR_DEV=false +NEXT_PUBLIC_USE_PROD_DB=false +NEXT_PUBLIC_ALLOW_ADMIN=true +NEXT_PUBLIC_ALLOW_APPLICANT=false \ No newline at end of file From 5201421e7023367e543f64c8ff10f3035be30138 Mon Sep 17 00:00:00 2001 From: JasonMun7 Date: Sun, 2 Mar 2025 14:42:51 -0500 Subject: [PATCH 04/11] Alert changes --- .../Admin/CoffeeChats/CoffeeChats.tsx | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx index 2a5a7b1db..59c960c48 100644 --- a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx +++ b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx @@ -63,17 +63,9 @@ const CoffeeChats: React.FC = () => { })); const archiveAllCoffeeChats = async () => { - if ( - !confirm( - 'Are you sure you want to archive all coffee chats? This action cannot be undone! :)' - ) - ) { - return; - } - try { await CoffeeChatAPI.archiveCoffeeChats(); - alert('All coffee chats have been archived successfully.'); + alert('All coffee chats have been archived successfully!! :)'); setIsLoading(true); } catch (error) { console.error('Error archiving coffee chats:', error); @@ -82,17 +74,9 @@ const CoffeeChats: React.FC = () => { }; const unarchiveAllCoffeeChats = async () => { - if ( - !confirm( - 'Are you sure you want to unarchive all coffee chats? This action cannot be undone! :)' - ) - ) { - return; - } - try { await CoffeeChatAPI.unarchiveCoffeeChats(); - alert('All coffee chats have been archived successfully.'); + alert('All coffee chats have been archived successfully!! :)'); setIsLoading(true); } catch (error) { console.error('Error archiving coffee chats:', error); From 462ff87a65a07e79d9a0dc89a9a32e0b6ea0d1a4 Mon Sep 17 00:00:00 2001 From: JasonMun7 Date: Sun, 2 Mar 2025 14:55:26 -0500 Subject: [PATCH 05/11] Made dao functions static --- backend/src/dao/CoffeeChatDao.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/dao/CoffeeChatDao.ts b/backend/src/dao/CoffeeChatDao.ts index 330449cff..dbb48ec80 100644 --- a/backend/src/dao/CoffeeChatDao.ts +++ b/backend/src/dao/CoffeeChatDao.ts @@ -140,7 +140,7 @@ export default class CoffeeChatDao extends BaseDao { /** * Archives all coffee chats by setting the isArchived field to true. */ - async archiveCoffeeChats(): Promise { + static async archiveCoffeeChats(): Promise { const coffeeChats = await coffeeChatsCollection.where('isArchived', '==', false).get(); const batch = db.batch(); @@ -154,7 +154,7 @@ export default class CoffeeChatDao extends BaseDao { /** * Unarchives all coffee chats by setting the isArchived field to false. */ - async unarchiveCoffeeChats(): Promise { + static async unarchiveCoffeeChats(): Promise { const coffeeChats = await coffeeChatsCollection.where('isArchived', '==', true).get(); const batch = db.batch(); From 3e01ba315389107faa5db21ae2df54532df9b0b5 Mon Sep 17 00:00:00 2001 From: JasonMun7 Date: Sun, 2 Mar 2025 15:00:40 -0500 Subject: [PATCH 06/11] Lint error --- backend/src/API/coffeeChatAPI.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/API/coffeeChatAPI.ts b/backend/src/API/coffeeChatAPI.ts index dd4791e8e..5fe93c358 100644 --- a/backend/src/API/coffeeChatAPI.ts +++ b/backend/src/API/coffeeChatAPI.ts @@ -151,7 +151,7 @@ export const archiveCoffeeChats = async (user: IdolMember): Promise => { ); } - await coffeeChatDao.archiveCoffeeChats(); + await CoffeeChatDao.archiveCoffeeChats(); }; /** @@ -167,7 +167,7 @@ export const unarchiveCoffeeChats = async (user: IdolMember): Promise => { ); } - await coffeeChatDao.unarchiveCoffeeChats(); + await CoffeeChatDao.unarchiveCoffeeChats(); }; /** From 6e17d4e72d87b9a6bf79bab6cd8ab23a509afe4a Mon Sep 17 00:00:00 2001 From: JasonMun7 Date: Sun, 2 Mar 2025 15:17:48 -0500 Subject: [PATCH 07/11] Added in confirmation alerts --- .../src/components/Admin/CoffeeChats/CoffeeChats.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx index 59c960c48..67218507b 100644 --- a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx +++ b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx @@ -63,6 +63,12 @@ const CoffeeChats: React.FC = () => { })); const archiveAllCoffeeChats = async () => { + if ( + !confirm('Are you sure you want to archive all coffee chats? This action cannot be undone.') + ) { + return; + } + try { await CoffeeChatAPI.archiveCoffeeChats(); alert('All coffee chats have been archived successfully!! :)'); @@ -74,6 +80,11 @@ const CoffeeChats: React.FC = () => { }; const unarchiveAllCoffeeChats = async () => { + if ( + !confirm('Are you sure you want to unarchive all coffee chats? This action cannot be undone.') + ) { + return; + } try { await CoffeeChatAPI.unarchiveCoffeeChats(); alert('All coffee chats have been archived successfully!! :)'); From 22d37624feef01d35290971a651a7703ff480591 Mon Sep 17 00:00:00 2001 From: JasonMun7 Date: Sun, 2 Mar 2025 15:20:41 -0500 Subject: [PATCH 08/11] Lint errors --- frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx index 67218507b..3e85ec93c 100644 --- a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx +++ b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx @@ -85,6 +85,7 @@ const CoffeeChats: React.FC = () => { ) { return; } + try { await CoffeeChatAPI.unarchiveCoffeeChats(); alert('All coffee chats have been archived successfully!! :)'); From 5fda56216a25b1be14ca0ab529aba07b9cef8dc3 Mon Sep 17 00:00:00 2001 From: JasonMun7 Date: Sun, 2 Mar 2025 15:24:14 -0500 Subject: [PATCH 09/11] Addressed lint error with confirm --- frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx index 3e85ec93c..6525b3fec 100644 --- a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx +++ b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx @@ -64,7 +64,9 @@ const CoffeeChats: React.FC = () => { const archiveAllCoffeeChats = async () => { if ( - !confirm('Are you sure you want to archive all coffee chats? This action cannot be undone.') + !window.confirm( + 'Are you sure you want to archive all coffee chats? This action cannot be undone.' + ) ) { return; } @@ -81,7 +83,9 @@ const CoffeeChats: React.FC = () => { const unarchiveAllCoffeeChats = async () => { if ( - !confirm('Are you sure you want to unarchive all coffee chats? This action cannot be undone.') + !window.confirm( + 'Are you sure you want to unarchive all coffee chats? This action cannot be undone.' + ) ) { return; } From 3d007cccf75cb635f05875fd1b1a82fd43f004ce Mon Sep 17 00:00:00 2001 From: JasonMun7 Date: Wed, 5 Mar 2025 16:01:15 -0500 Subject: [PATCH 10/11] Added in deletion functionality and popup modal, also got rid of unarchived button --- backend/src/API/coffeeChatAPI.ts | 16 --------- backend/src/api.ts | 8 +---- backend/src/dao/CoffeeChatDao.ts | 23 ++++--------- frontend/src/API/CoffeeChatAPI.ts | 13 ------- .../Admin/CoffeeChats/CoffeeChats.tsx | 34 +++++-------------- 5 files changed, 16 insertions(+), 78 deletions(-) diff --git a/backend/src/API/coffeeChatAPI.ts b/backend/src/API/coffeeChatAPI.ts index 5fe93c358..46d32ec0a 100644 --- a/backend/src/API/coffeeChatAPI.ts +++ b/backend/src/API/coffeeChatAPI.ts @@ -154,22 +154,6 @@ export const archiveCoffeeChats = async (user: IdolMember): Promise => { await CoffeeChatDao.archiveCoffeeChats(); }; -/** - * Unarchives all coffee chats by setting the isArchived field to false. - * @param user - The user making the request. - * @throws PermissionError if the user does not have permissions. - */ -export const unarchiveCoffeeChats = async (user: IdolMember): Promise => { - const canUnarchive = await PermissionsManager.isLeadOrAdmin(user); - if (!canUnarchive) { - throw new PermissionError( - `User with email ${user.email} does not have permission to unarchive coffee chats.` - ); - } - - await CoffeeChatDao.unarchiveCoffeeChats(); -}; - /** * Gets the coffee chat bingo board */ diff --git a/backend/src/api.ts b/backend/src/api.ts index 3d9de4845..45930ef00 100644 --- a/backend/src/api.ts +++ b/backend/src/api.ts @@ -44,8 +44,7 @@ import { runAutoChecker, notifyMemberCoffeeChat, getCoffeeChatSuggestions, - archiveCoffeeChats, - unarchiveCoffeeChats + archiveCoffeeChats } from './API/coffeeChatAPI'; import { allSignInForms, @@ -353,11 +352,6 @@ loginCheckedPatch('/coffee-chat/archive', async (_, user) => { return { message: 'All coffee chats archived successfully.' }; }); -loginCheckedPatch('/coffee-chat/unarchive', async (_, user) => { - await unarchiveCoffeeChats(user); - return { message: 'All coffee chats unarchived successfully.' }; -}); - loginCheckedGet('/coffee-chat-bingo-board', async () => { const board = await getCoffeeChatBingoBoard(); return { board }; diff --git a/backend/src/dao/CoffeeChatDao.ts b/backend/src/dao/CoffeeChatDao.ts index dbb48ec80..6f770a08d 100644 --- a/backend/src/dao/CoffeeChatDao.ts +++ b/backend/src/dao/CoffeeChatDao.ts @@ -141,28 +141,17 @@ export default class CoffeeChatDao extends BaseDao { * Archives all coffee chats by setting the isArchived field to true. */ static async archiveCoffeeChats(): Promise { - const coffeeChats = await coffeeChatsCollection.where('isArchived', '==', false).get(); - const batch = db.batch(); + const coffeeChatsToDelete = await coffeeChatsCollection.where('isArchived', '==', true).get(); + const deletePromises = coffeeChatsToDelete.docs.map((doc) => doc.ref.delete()); - coffeeChats.docs.forEach((doc) => { - batch.update(doc.ref, { isArchived: true }); - }); - - await batch.commit(); - } - - /** - * Unarchives all coffee chats by setting the isArchived field to false. - */ - static async unarchiveCoffeeChats(): Promise { - const coffeeChats = await coffeeChatsCollection.where('isArchived', '==', true).get(); + const coffeeChatsToArchive = await coffeeChatsCollection.where('isArchived', '==', false).get(); const batch = db.batch(); - coffeeChats.docs.forEach((doc) => { - batch.update(doc.ref, { isArchived: false }); + coffeeChatsToArchive.docs.forEach((doc) => { + batch.update(doc.ref, { isArchived: true }); }); - await batch.commit(); + await Promise.all([Promise.all(deletePromises), batch.commit()]); } /** diff --git a/frontend/src/API/CoffeeChatAPI.ts b/frontend/src/API/CoffeeChatAPI.ts index bd7ea5485..cbefbfc45 100644 --- a/frontend/src/API/CoffeeChatAPI.ts +++ b/frontend/src/API/CoffeeChatAPI.ts @@ -51,19 +51,6 @@ export default class CoffeeChatAPI { }); } - public static async unarchiveCoffeeChats(): Promise { - return APIWrapper.patch(`${backendURL}/coffee-chat/unarchive`).then((res) => { - if (res.data.error) { - Emitters.generalError.emit({ - headerMsg: "Couldn't unarchive coffee chats", - contentMsg: `Error: ${res.data.error}` - }); - } else { - console.log(res.data.message); - } - }); - } - public static async getCoffeeChatBingoBoard(): Promise { const res = await APIWrapper.get(`${backendURL}/coffee-chat-bingo-board`).then( (res) => res.data diff --git a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx index 6525b3fec..99822e6d4 100644 --- a/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx +++ b/frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx @@ -6,6 +6,7 @@ import styles from './CoffeeChats.module.css'; import CoffeeChatAPI from '../../../API/CoffeeChatAPI'; import { useMembers } from '../../Common/FirestoreDataProvider'; import CoffeeChatsBingoBoard from '../../Forms/CoffeeChatsForm/CoffeeChatsBingoBoard'; +import { Emitters } from '../../../utils'; const CoffeeChats: React.FC = () => { const [bingoBoard, setBingoBoard] = useState([[]]); @@ -73,30 +74,16 @@ const CoffeeChats: React.FC = () => { try { await CoffeeChatAPI.archiveCoffeeChats(); - alert('All coffee chats have been archived successfully!! :)'); + Emitters.generalSuccess.emit({ + headerMsg: 'Success', + contentMsg: 'All coffee chats have been archived successfully!! :)' + }); setIsLoading(true); } catch (error) { - console.error('Error archiving coffee chats:', error); - alert('Failed to archive coffee chats.'); - } - }; - - const unarchiveAllCoffeeChats = async () => { - if ( - !window.confirm( - 'Are you sure you want to unarchive all coffee chats? This action cannot be undone.' - ) - ) { - return; - } - - try { - await CoffeeChatAPI.unarchiveCoffeeChats(); - alert('All coffee chats have been archived successfully!! :)'); - setIsLoading(true); - } catch (error) { - console.error('Error archiving coffee chats:', error); - alert('Failed to archive coffee chats.'); + Emitters.generalError.emit({ + headerMsg: 'Error', + contentMsg: 'Failed to archive the coffee chats' + }); } }; @@ -165,9 +152,6 @@ const CoffeeChats: React.FC = () => { -
Date: Sun, 9 Mar 2025 15:13:23 -0400 Subject: [PATCH 11/11] removed console statement --- frontend/src/API/CoffeeChatAPI.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/src/API/CoffeeChatAPI.ts b/frontend/src/API/CoffeeChatAPI.ts index cbefbfc45..ee279be42 100644 --- a/frontend/src/API/CoffeeChatAPI.ts +++ b/frontend/src/API/CoffeeChatAPI.ts @@ -45,8 +45,6 @@ export default class CoffeeChatAPI { headerMsg: "Couldn't archive coffee chats", contentMsg: `Error: ${res.data.error}` }); - } else { - console.log(res.data.message); } }); }