diff --git a/apps/antalmanac/src/actions/AppStoreActions.ts b/apps/antalmanac/src/actions/AppStoreActions.ts index 8caab3f47..eb937ef40 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, @@ -182,13 +187,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 toggleTheme = (radioGroupEvent: React.ChangeEvent) => { diff --git a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx index bebb71fce..e4eb048ea 100644 --- a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx +++ b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx @@ -17,12 +17,13 @@ import { 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'; /** @@ -100,9 +101,9 @@ function handleClear() { } } -function createCopyHandler(index: number) { +function createCopyHandler(index: number, options: CopyScheduleOptions) { return () => { - copySchedule(index); + copySchedule(index, options); }; } @@ -118,6 +119,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(() => { /** @@ -148,12 +163,14 @@ function CopyScheduleButton() { Copy to {name} ))} - Copy to All Schedules + + Copy to All Schedules + )}