diff --git a/src/commons/sagas/RequestsSaga.ts b/src/commons/sagas/RequestsSaga.ts index 69f4938dfb..c07d5a71fb 100644 --- a/src/commons/sagas/RequestsSaga.ts +++ b/src/commons/sagas/RequestsSaga.ts @@ -1014,11 +1014,12 @@ export const putAssessmentConfigs = async ( return resp; }; +// Notification related request export const putNotificationConfigs = async ( tokens: Tokens, notificationConfigs: NotificationConfiguration[] ) => { - return await request(`notifications/config`, 'PUT', { + return await request(`courses/${courseIdWithoutPrefix()}/admin/notifications/config`, 'PUT', { ...tokens, body: notificationConfigs, noHeaderAccept: true @@ -1081,11 +1082,15 @@ export const removeTimeOptions = async ( tokens: Tokens, timeOptionIds: number[] ): Promise => { - const resp = await request(`notifications/options`, 'DELETE', { - ...tokens, - body: timeOptionIds, - noHeaderAccept: true - }); + const resp = await request( + `courses/${courseIdWithoutPrefix()}/admin/notifications/options`, + 'DELETE', + { + ...tokens, + body: timeOptionIds, + noHeaderAccept: true + } + ); return resp; }; @@ -1094,7 +1099,7 @@ export const putTimeOptions = async ( tokens: Tokens, timeOptions: TimeOption[] ): Promise => { - const resp = await request(`notifications/options`, 'PUT', { + const resp = await request(`courses/${courseIdWithoutPrefix()}/notifications/options`, 'PUT', { ...tokens, body: timeOptions, noHeaderAccept: true @@ -1106,9 +1111,13 @@ export const putTimeOptions = async ( export const getNotificationConfigs = async ( tokens: Tokens ): Promise => { - const resp = await request(`notifications/config/${courseIdWithoutPrefix()}`, 'GET', { - ...tokens - }); + const resp = await request( + `courses/${courseIdWithoutPrefix()}/admin/notifications/config`, + 'GET', + { + ...tokens + } + ); if (!resp || !resp.ok) { return null; } @@ -1120,9 +1129,13 @@ export const getConfigurableNotificationConfigs = async ( tokens: Tokens, courseRegId: number ): Promise => { - const resp = await request(`notifications/config/user/${courseRegId}`, 'GET', { - ...tokens - }); + const resp = await request( + `courses/${courseIdWithoutPrefix()}/notifications/config/user/${courseRegId}`, + 'GET', + { + ...tokens + } + ); if (!resp || !resp.ok) { return null; } @@ -1155,13 +1168,17 @@ export const putNotificationPreferences = async ( notiPrefs: NotificationPreference[], courseRegId: number ): Promise => { - const resp = await request(`notifications/preferences`, 'PUT', { - ...tokens, - body: notiPrefs.map(pref => { - return { ...pref, courseRegId: courseRegId }; - }), - noHeaderAccept: true - }); + const resp = await request( + `courses/${courseIdWithoutPrefix()}/notifications/preferences`, + 'PUT', + { + ...tokens, + body: notiPrefs.map(pref => { + return { ...pref, courseRegId: courseRegId }; + }), + noHeaderAccept: true + } + ); return resp; }; diff --git a/src/pages/academy/adminPanel/subcomponents/NotificationConfigPanel.tsx b/src/pages/academy/adminPanel/subcomponents/NotificationConfigPanel.tsx index 034b56ab43..4eec4e5c64 100644 --- a/src/pages/academy/adminPanel/subcomponents/NotificationConfigPanel.tsx +++ b/src/pages/academy/adminPanel/subcomponents/NotificationConfigPanel.tsx @@ -15,7 +15,6 @@ import { NotificationConfiguration, TimeOption } from 'src/commons/application/t import { useTypedSelector } from 'src/commons/utils/Hooks'; import BooleanCell from './assessmentConfigPanel/BooleanCell'; -import SelectCell from './notificationConfigPanel/SelectCell'; import TimeOptionCell from './notificationConfigPanel/TimeOptionCell'; const NotificationConfigPanel = () => { @@ -94,16 +93,21 @@ const NotificationConfigPanel = () => { return params.data!.notificationType.forStaff ? 'Staff' : 'Student'; }; + const notificationTypeId: ValueFormatterFunc = params => { + const id = params.data!.notificationType?.id || 0; + return String(id); + }; + const columnDefs: ColDef[] = [ { - headerName: 'Notification Type', - field: 'notificationType.name', + headerName: 'Assessment Type', + field: 'assessmentConfig.type', + valueFormatter: assessmentTypeFormatter, rowDrag: true }, { - headerName: 'Assessment Type', - field: 'assessmentConfig.type', - valueFormatter: assessmentTypeFormatter + headerName: 'Notification Type', + field: 'notificationType.name' }, { headerName: 'Recipients', @@ -119,16 +123,20 @@ const NotificationConfigPanel = () => { // headerName: 'Past 30 Days', // field: 'notificationType.id' // }, + { - headerName: 'Reminder Time Options (hours)', + headerName: 'Default Reminder Time(hours)', field: 'timeOptions', cellRenderer: TimeOptionCell, cellRendererParams: { setStateHandler: setTimeOptions, setDelete: addTimeOptionsToDelete, - field: 'timeOptions' + field: 'timeOptions', + typeId: notificationTypeId } }, + + /* { headerName: 'Default Reminder (hours)', field: 'timeOptions', @@ -138,6 +146,7 @@ const NotificationConfigPanel = () => { field: 'timeOptions' } }, + */ { headerName: 'Enabled', field: 'isEnabled', diff --git a/src/pages/academy/adminPanel/subcomponents/notificationConfigPanel/SelectCell.tsx b/src/pages/academy/adminPanel/subcomponents/notificationConfigPanel/SelectCell.tsx deleted file mode 100644 index 5d94ac3390..0000000000 --- a/src/pages/academy/adminPanel/subcomponents/notificationConfigPanel/SelectCell.tsx +++ /dev/null @@ -1,77 +0,0 @@ -import { Button, MenuItem } from '@blueprintjs/core'; -import { ItemRenderer, Select2 } from '@blueprintjs/select'; -import React from 'react'; -import { NotificationConfiguration, TimeOption } from 'src/commons/application/types/SessionTypes'; -import { KeysOfType } from 'src/commons/utils/TypeHelper'; - -type SelectCellProps = OwnProps; - -type OwnProps = { - data: NotificationConfiguration; - rowIndex: number; - field: KeysOfType; - setStateHandler: (rowIndex: number, value: any) => void; -}; - -const SelectCell: React.FC = props => { - const [selectedOption, setSelectedOption] = React.useState(); - const timeOptions: TimeOption[] = props.data[props.field]; - timeOptions.sort((to1, to2) => to1.minutes - to2.minutes); - - const getUserFriendlyText = (option: TimeOption) => - option.minutes >= 60 - ? `${Math.round((option.minutes / 60) * 100) / 100} hour(s)` - : `${option.minutes} minute(s)`; - - const renderOption: ItemRenderer = ( - option: TimeOption, - { handleClick, handleFocus, modifiers, query } - ) => { - return ( - - ); - }; - - const defaultTimeOptions = timeOptions.filter(to => to.isDefault); - if (defaultTimeOptions.length === 1) { - if (!selectedOption || selectedOption.id !== defaultTimeOptions[0].id) { - setSelectedOption(defaultTimeOptions[0]); - } - } - - const handleSelect = (option: TimeOption) => { - setSelectedOption(option); - const updatedTimeOptions: TimeOption[] = timeOptions.map(timeOption => { - return { - ...timeOption, - isDefault: timeOption.id === option.id && timeOption.minutes === option.minutes - }; - }); - props.setStateHandler(props.rowIndex, updatedTimeOptions); - }; - - return ( - - filterable={false} - items={timeOptions} - itemRenderer={renderOption} - onItemSelect={handleSelect} - noResults={} - > -