Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coffee Chat Archive/Unarchive Button #872

Merged
merged 23 commits into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3c599b5
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 3, 2024
f8eee4b
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 5, 2024
e0639af
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 5, 2024
5a8d139
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 6, 2024
b538a07
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 19, 2024
dd7902e
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 21, 2024
f7e1419
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 23, 2024
bf512e5
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Dec 23, 2024
2eb9066
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Feb 4, 2025
503b1d7
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Feb 11, 2025
d61f71c
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Feb 15, 2025
ff14d05
Merge branch 'main' of https://github.com/cornell-dti/idol
JasonMun7 Feb 27, 2025
dbde9c4
Completed Archive/Unarchive functionality
JasonMun7 Mar 2, 2025
671f284
Added in patch
JasonMun7 Mar 2, 2025
589781a
added back in the examples
JasonMun7 Mar 2, 2025
5201421
Alert changes
JasonMun7 Mar 2, 2025
462ff87
Made dao functions static
JasonMun7 Mar 2, 2025
3e01ba3
Lint error
JasonMun7 Mar 2, 2025
6e17d4e
Added in confirmation alerts
JasonMun7 Mar 2, 2025
22d3762
Lint errors
JasonMun7 Mar 2, 2025
5fda562
Addressed lint error with confirm
JasonMun7 Mar 2, 2025
3d007cc
Added in deletion functionality and popup modal, also got rid of unar…
JasonMun7 Mar 5, 2025
c3ee747
removed console statement
JasonMun7 Mar 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions backend/src/API/coffeeChatAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ export const clearAllCoffeeChats = async (user: IdolMember): Promise<void> => {
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<void> => {
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();
};

/**
* Gets the coffee chat bingo board
*/
Expand Down
13 changes: 12 additions & 1 deletion backend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ import {
checkMemberMeetsCategory,
runAutoChecker,
notifyMemberCoffeeChat,
getCoffeeChatSuggestions
getCoffeeChatSuggestions,
archiveCoffeeChats
} from './API/coffeeChatAPI';
import {
allSignInForms,
Expand Down Expand Up @@ -204,6 +205,11 @@ const loginCheckedPut = (
handler: (req: Request, user: IdolMember) => Promise<Record<string, unknown>>
) => router.put(path, loginCheckedHandler(handler));

const loginCheckedPatch = (
path: string,
handler: (req: Request, user: IdolMember) => Promise<Record<string, unknown>>
) => router.patch(path, loginCheckedHandler(handler));

// Members
router.get('/member', async (req, res) => {
const type = req.query.type as string | undefined;
Expand Down Expand Up @@ -341,6 +347,11 @@ 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.' };
});

loginCheckedGet('/coffee-chat-bingo-board', async () => {
const board = await getCoffeeChatBingoBoard();
return { board };
Expand Down
17 changes: 17 additions & 0 deletions backend/src/dao/CoffeeChatDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ export default class CoffeeChatDao extends BaseDao<CoffeeChat, DBCoffeeChat> {
await deleteCollection(db, 'coffee-chats', 500);
}

/**
* Archives all coffee chats by setting the isArchived field to true.
*/
static async archiveCoffeeChats(): Promise<void> {
const coffeeChatsToDelete = await coffeeChatsCollection.where('isArchived', '==', true).get();
const deletePromises = coffeeChatsToDelete.docs.map((doc) => doc.ref.delete());

const coffeeChatsToArchive = await coffeeChatsCollection.where('isArchived', '==', false).get();
const batch = db.batch();

coffeeChatsToArchive.docs.forEach((doc) => {
batch.update(doc.ref, { isArchived: true });
});

await Promise.all([Promise.all(deletePromises), batch.commit()]);
}

/**
* Gets the coffee chat bingo board
*/
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/API/APIWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ export default class APIWrapper {
.then((resOrErr) => this.responseMiddleware(resOrErr));
}

public static async patch(
url: string,
body: unknown = {},
config = {}
): Promise<APIProcessedResponse> {
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<unknown> | AxiosError
): APIProcessedResponse {
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/API/CoffeeChatAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ export default class CoffeeChatAPI {
await APIWrapper.delete(`${backendURL}/coffee-chat/${uuid}`);
}

public static async archiveCoffeeChats(): Promise<void> {
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}`
});
}
});
}

public static async getCoffeeChatBingoBoard(): Promise<string[][]> {
const res = await APIWrapper.get(`${backendURL}/coffee-chat-bingo-board`).then(
(res) => res.data
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/components/Admin/CoffeeChats/CoffeeChats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[][]>([[]]);
Expand Down Expand Up @@ -62,6 +63,30 @@ const CoffeeChats: React.FC = () => {
value: member.netid
}));

const archiveAllCoffeeChats = async () => {
if (
!window.confirm(
'Are you sure you want to archive all coffee chats? This action cannot be undone.'
)
) {
return;
}

try {
await CoffeeChatAPI.archiveCoffeeChats();
Emitters.generalSuccess.emit({
headerMsg: 'Success',
contentMsg: 'All coffee chats have been archived successfully!! :)'
});
setIsLoading(true);
} catch (error) {
Emitters.generalError.emit({
headerMsg: 'Error',
contentMsg: 'Failed to archive the coffee chats'
});
}
};

return (
<div className={styles.flexContainer}>
<div>
Expand Down Expand Up @@ -124,6 +149,9 @@ const CoffeeChats: React.FC = () => {
<Button onClick={() => setSelectedMember(null)} disabled={selectedMember == null}>
Review All Coffee Chats
</Button>
<Button onClick={archiveAllCoffeeChats} disabled={selectedMember !== null}>
Archive All Coffee Chats
</Button>
<div className={styles.dropdownButton}>
<Dropdown
placeholder={DEAFAULT_MEMBER_DROPDOWN_TEXT}
Expand Down
Loading