diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts
index 7f4da1faa..4b0ba2e45 100644
--- a/apps/antalmanac/src/actions/AppStoreActions.ts
+++ b/apps/antalmanac/src/actions/AppStoreActions.ts
@@ -12,6 +12,11 @@ import AppStore from '$stores/AppStore';
import trpc from '$lib/api/trpc';
import { courseNumAsDecimal } from '$lib/analytics';
+export interface CopyScheduleOptions {
+ onSuccess: (index: number) => unknown;
+ onError: (index: number) => unknown;
+}
+
export const addCourse = (
section: WebsocSection,
courseDetails: CourseDetails,
@@ -181,13 +186,18 @@ export const changeCourseColor = (sectionCode: string, term: string, newColor: s
AppStore.changeCourseColor(sectionCode, term, newColor);
};
-export const copySchedule = (to: number) => {
+export const copySchedule = (to: number, options?: CopyScheduleOptions) => {
logAnalytics({
category: analyticsEnum.addedClasses.title,
action: analyticsEnum.addedClasses.actions.COPY_SCHEDULE,
});
- AppStore.copySchedule(to);
+ try {
+ AppStore.copySchedule(to);
+ options?.onSuccess(to);
+ } catch (error) {
+ options?.onError(to);
+ }
};
export const addSchedule = (scheduleName: string) => {
diff --git a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx
index bc976797c..e56f8f65c 100644
--- a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx
+++ b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx
@@ -5,12 +5,13 @@ import { Box, Chip, IconButton, Menu, MenuItem, Paper, SxProps, TextField, Toolt
import { ContentCopy, DeleteOutline } from '@mui/icons-material';
import { AACourse } from '@packages/antalmanac-types';
+import { useSnackbar } from 'notistack';
import { ColumnToggleButton } from '../CoursePane/CoursePaneButtonRow';
import SectionTableLazyWrapper from '../SectionTable/SectionTableLazyWrapper';
import CustomEventDetailView from './CustomEventDetailView';
import AppStore from '$stores/AppStore';
import analyticsEnum, { logAnalytics } from '$lib/analytics';
-import { clearSchedules, copySchedule, updateScheduleNote } from '$actions/AppStoreActions';
+import { CopyScheduleOptions, clearSchedules, copySchedule, updateScheduleNote } from '$actions/AppStoreActions';
import { clickToCopy } from '$lib/helpers';
/**
@@ -88,9 +89,9 @@ function handleClear() {
}
}
-function createCopyHandler(index: number) {
+function createCopyHandler(index: number, options: CopyScheduleOptions) {
return () => {
- copySchedule(index);
+ copySchedule(index, options);
};
}
@@ -106,6 +107,20 @@ function ClearScheduleButton() {
function CopyScheduleButton() {
const [scheduleNames, setScheduleNames] = useState(AppStore.getScheduleNames());
+ const { enqueueSnackbar } = useSnackbar();
+
+ const options = useMemo(() => {
+ return {
+ onSuccess: (index: number) => {
+ const name = index === scheduleNames.length ? 'All Schedules' : scheduleNames[index];
+ enqueueSnackbar(`Schedule copied to ${name}.`, { variant: 'success' });
+ },
+ onError: (index: number) => {
+ const name = index === scheduleNames.length ? 'All Schedules' : scheduleNames[index];
+ enqueueSnackbar(`Could not copy schedule to ${name}.`, { variant: 'error' });
+ },
+ };
+ }, [enqueueSnackbar, scheduleNames]);
useEffect(() => {
/**
@@ -136,12 +151,14 @@ function CopyScheduleButton() {
))}
-
+
>
)}