Skip to content

Commit

Permalink
cleaned up code and commented out toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristen Yee authored and Kristen Yee committed Apr 18, 2024
1 parent aa8a09f commit 5168ecd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 161 deletions.
162 changes: 26 additions & 136 deletions src/components/Notifications/AccountNotification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
GridItem,
Text,
Link,
useToast,
// useToast,
} from '@chakra-ui/react';

const AccountNotification = ({
Expand All @@ -27,7 +27,7 @@ const AccountNotification = ({
declineAfterTimer,
setDeclineAfterTimer,
}) => {
const toast = useToast();
// const toast = useToast();
const [accounts, setAccounts] = useState(notificationBlock.getNotificationData().accounts);
const [disableChildrenButtons, setDisableChildrenButtons] = useState(false);

Expand All @@ -37,120 +37,74 @@ const AccountNotification = ({

const [removeNotificationBlock, setRemoveNotificationBlock] = useState(false);
const [timeoutId, setTimeoutId] = useState(undefined);
// let timeoutId = undefined;

const acceptAll = async accounts => {
console.log('calling accept all function');

const timeId = setTimeout(async () => {
console.log("calling approve callback map");
await Promise.all(
accounts.map(async account => {
await account.approveCallback();
}),
);
console.log("set remove notif block true");
setRemoveNotificationBlock(true);
setApproveAfterTimer(true);
}, 5000); // set 5 sec timer for accept all requests
console.log("set timeoutid in accept all: ", timeId);
setTimeoutId(timeId);

// toast({
// title: `Approved ${accounts?.length} accounts.`,
// status: 'success',
// duration: 9000,
// isClosable: true,
// });

// removeEntry(notificationBlock.key);
console.log('done with accept all');
};

const declineAll = async accounts => {
console.log('calling decline all function');

const timeId = setTimeout(async () => {
await Promise.all(
accounts.map(async account => {
await account.declineCallback();
}),
);
console.log("set remove notif block true");
setRemoveNotificationBlock(true);
setDeclineAfterTimer(true);
}, 5000); // set 5 sec timer for accept all requests
setTimeoutId(timeId);
// toast({
// title: `Declined ${accounts?.length} accounts.`,
// status: 'info',
// duration: 9000,
// isClosable: true,
// });
// removeEntry(notificationBlock.key);
console.log('done with decline all function');
};

const undoAll = async () => {
console.log('calling undo all function');
console.log("clearing timeoutid from undoall: ", timeoutId);
clearTimeout(timeoutId);
setTimeoutId(undefined);
console.log("undo called, set remove notif block false");
setRemoveNotificationBlock(false);
setApproveAfterTimer(false);
setDeclineAfterTimer(false);
console.log('done undoall function');
};

// this is really buggy
useEffect(() => {
console.log('approveaftertimer or removenoticationblock value changed', approveAfterTimer, removeNotificationBlock);
if (approveAfterTimer && removeNotificationBlock) {
console.log('approveafter timer = true and remove notification block = true');
console.log("REMOVE NOTIF BLOCK HERE");

toast({
title: `Approved.`,
status: 'success',
duration: 9000,
isClosable: true,
});

removeEntry(notificationBlock.key);
// toast({
// title: `Approved.`,
// status: 'success',
// duration: 9000,
// isClosable: true,
// });
} else if (declineAfterTimer && removeNotificationBlock) {
console.log('decline after timer = true and remove notification block = true');
console.log("REMOVE NOTIF BLOCK HERE");

toast({
title: `Declined.`,
status: 'info',
duration: 9000,
isClosable: true,
});
removeEntry(notificationBlock.key);
// toast({
// title: `Declined.`,
// status: 'info',
// duration: 9000,
// isClosable: true,
// });
} else if (approveAfterTimer) {
console.log('approveafter timer = true and remove notification block = false');
console.log("remove 1 account here");
console.log('idToRemove', idToRemove);
setAccounts(accounts => accounts.filter(account => account.id !== idToRemove));
toast({
title: `Approved.`,
status: 'success',
duration: 9000,
isClosable: true,
});
// toast({
// title: `Approved.`,
// status: 'success',
// duration: 9000,
// isClosable: true,
// });
} else if (declineAfterTimer) {
console.log('decline after timer = true and remove notification block = false');
console.log("remove 1 account here");
console.log('idToRemove', idToRemove);
setAccounts(accounts => accounts.filter(account => account.id !== idToRemove));
toast({
title: `Declined.`,
status: 'info',
duration: 9000,
isClosable: true,
});
// toast({
// title: `Declined.`,
// status: 'info',
// duration: 9000,
// isClosable: true,
// });
}
}, [approveAfterTimer, declineAfterTimer, removeNotificationBlock]);

Expand Down Expand Up @@ -178,7 +132,6 @@ const AccountNotification = ({
declineAll(accounts);
}}
undoCallback={() => {
console.log('but undo function here');
undoAll(accounts);
}}
pl="3.25rem"
Expand Down Expand Up @@ -220,7 +173,6 @@ const AccountNotification = ({
}}
undoCallback={() => {
setDisableChildrenButtons(false);
console.log('but undo function here');
undoAll(accounts);
}}
/>
Expand All @@ -240,35 +192,11 @@ const AccountNotification = ({
declineText="Decline"
acceptCallback={async () => {
await approveCallback();
// console.log('check approveAfterTimer');

// if (approveAfterTimer) {
// // toast({
// // title: `Approved ${email}.`,
// // status: 'success',
// // duration: 9000,
// // isClosable: true,
// // });
// // setAccounts(accounts =>
// // accounts.filter(account => account.id !== id),
// // );
// console.log('useEffect instead lol');
// }
}}
declineCallback={async () => {
await declineCallback();
// toast({
// title: `Declined ${email}.`,
// status: 'info',
// duration: 9000,
// isClosable: true,
// });
// setAccounts(accounts =>
// accounts.filter(account => account.id !== id),
// );
}}
undoCallback={() => {
console.log('but undo function here');
undoCallback();
}}
disableChildrenButtons={disableChildrenButtons}
Expand Down Expand Up @@ -369,7 +297,6 @@ const AccountButtonGroup = ({
color="blue.600"
decoration="underline"
onClick={() => {
console.log('trying to undo');
setAcceptState(undefined);
setDeclineState(undefined);
setApproveClicked(false);
Expand All @@ -388,7 +315,6 @@ const AccountButtonGroup = ({
color="blue.600"
decoration="underline"
onClick={() => {
console.log('trying to undo');
setAcceptState(undefined);
setDeclineState(undefined);
setDeclineClicked(false);
Expand All @@ -403,42 +329,6 @@ const AccountButtonGroup = ({
</>
)}
</>
// <ButtonGroup gap="2" {...chakraProps}>
// <Button
// onClick={() => {
// setAcceptState('loading');
// setDeclineState('disabled');
// // console.log("calling accept callback");
// setApproveClicked(true);
// acceptCallback();
// }}
// backgroundColor="blue.500"
// color="white"
// fontSize="sm"
// h="6"
// fontWeight="normal"
// isLoading={acceptState === 'loading'}
// isDisabled={acceptState === 'disabled' || disableChildrenButtons === true}
// >
// {acceptText}
// </Button>
// <Button
// onClick={() => {
// setDeclineState('loading');
// setAcceptState('disabled');
// declineCallback();
// }}
// backgroundColor="gray.200"
// color="black"
// fontSize="sm"
// h="6"
// fontWeight="normal"
// isLoading={declineState === 'loading'}
// isDisabled={declineState === 'disabled' || disableChildrenButtons === true}
// >
// {declineText}
// </Button>
// </ButtonGroup>
);
};
AccountButtonGroup.propTypes = {
Expand Down
25 changes: 0 additions & 25 deletions src/components/Notifications/Notifications.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,63 +26,38 @@ const Notifications = () => {
const today = useMemo(() => new Date(), []);

const undoChanges = () => {
console.log('undoing changes now !!!');
clearTimeout(timeoutId);
timeoutId = undefined;
};

const approveAccount = async id => {
console.log('about to approve: ' + id);

// Start timer
const timeId = setTimeout(async () => {
try {
await NPOBackend.put(`/users/approve/${id}`);
} catch (e) {
console.log(e);
}
console.log("done approving account!");
setidToRemove(id);
console.log('setApproveAfterTimer called');
setApproveAfterTimer(true);
}, 5000); // 5 second delay
timeoutId = timeId;
};

const declineAccount = async id => {
console.log('about to decline: ' + id);

// Start timer
const timeId = setTimeout(async () => {
try {
await NPOBackend.delete(`/users/${id}`);
} catch (e) {
console.log(e);
}
console.log("done decline account!");
setidToRemove(id);
console.log('setDeclineAfterTimer called');
setDeclineAfterTimer(true);
}, 5000); // 5 second delay
timeoutId = timeId;
};

// const approveAccount = async id => {
// try {
// await NPOBackend.put(`/users/approve/${id}`);
// } catch (e) {
// console.log(e);
// }
// };

// const declineAccount = async id => {
// try {
// await NPOBackend.delete(`/users/${id}`);
// } catch (e) {
// console.log(e);
// }
// };

const removeNotificationEntry = key => {
setNotificationList(notificationBlocks =>
notificationBlocks.filter(block => block.getKey() !== key),
Expand Down

0 comments on commit 5168ecd

Please sign in to comment.