-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Front end for Fixed/delete action dropdown (#2041)
* back end updates for feedback api * update tests * update feedback test * add new migration files & update tests for backend * update enums && lint * update migrations * add missing enum * update tests * update resource * fix migration error * add dropdown * push updates * touch ups to ui * make button only visible to superusers * fix import error * add when component * update front end tests * update feedback modal test * add use effect to reload when switching between archived & regular listing * duplkicate imports
- Loading branch information
1 parent
d7ed49b
commit a7cb0ab
Showing
8 changed files
with
165 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, { useMemo } from 'react'; | ||
import { MenuItem, Select } from '@mui/material'; | ||
import { Feedback, FeedbackStatusEnum } from 'models/feedback'; | ||
import { useAppDispatch } from 'hooks'; | ||
import { Palette } from 'styles/Theme'; | ||
import { updateFeedback, deleteFeedback } from 'services/feedbackService'; | ||
import { openNotification } from 'services/notificationService/notificationSlice'; | ||
import { openNotificationModal } from 'services/notificationModalService/notificationModalSlice'; | ||
|
||
interface ActionDropDownItem { | ||
value: number; | ||
label: string; | ||
action?: () => void; | ||
condition?: boolean; | ||
} | ||
export const ActionsDropDown = ({ feedback, reload }: { feedback: Feedback; reload: () => void }) => { | ||
const dispatch = useAppDispatch(); | ||
const isArchived = feedback.status == FeedbackStatusEnum.Archived; | ||
const canEditFeedback = (): boolean => { | ||
return true; | ||
}; | ||
|
||
const archiveFeedback = async () => { | ||
try { | ||
await updateFeedback(feedback.id, { ...feedback, status: FeedbackStatusEnum.Archived }); | ||
dispatch(openNotification({ severity: 'success', text: 'Feedback has been archived.' })); | ||
reload(); | ||
} catch (error) { | ||
dispatch(openNotification({ severity: 'error', text: 'Error occurred while archiving feedback.' })); | ||
} | ||
}; | ||
|
||
const removeFeedback = async () => { | ||
dispatch( | ||
openNotificationModal({ | ||
open: true, | ||
data: { | ||
header: 'Delete Feedback', | ||
subText: [ | ||
{ text: 'You will be permanently deleting this feedback.' }, | ||
{ text: 'Please click the Cancel or Confirm button to continue.', bold: true }, | ||
], | ||
handleConfirm: async () => { | ||
try { | ||
await deleteFeedback(feedback.id); | ||
dispatch(openNotification({ severity: 'success', text: 'Feedback has been deleted.' })); | ||
reload(); | ||
} catch (error) { | ||
dispatch( | ||
openNotification({ | ||
severity: 'error', | ||
text: 'Error occurred while deleting feedback.', | ||
}), | ||
); | ||
} | ||
}, | ||
}, | ||
type: 'confirm', | ||
}), | ||
); | ||
}; | ||
|
||
const ITEMS: ActionDropDownItem[] = useMemo( | ||
() => [ | ||
{ | ||
value: 1, | ||
label: 'Mark As Resolved', | ||
action: () => { | ||
archiveFeedback(); | ||
}, | ||
condition: canEditFeedback() && !isArchived, | ||
}, | ||
{ | ||
value: 2, | ||
label: 'Delete Feedback', | ||
action: () => { | ||
removeFeedback(); | ||
}, | ||
condition: canEditFeedback(), | ||
}, | ||
], | ||
[feedback.id], | ||
); | ||
|
||
return ( | ||
<Select | ||
id={`action-drop-down-${feedback.id}`} | ||
value={0} | ||
fullWidth | ||
size="small" | ||
sx={{ backgroundColor: 'white', color: Palette.info.main }} | ||
> | ||
<MenuItem value={0} sx={{ fontStyle: 'italic', height: '2em' }} color="info" disabled> | ||
{'(Select One)'} | ||
</MenuItem> | ||
{ITEMS.filter((item) => item.condition).map((item) => ( | ||
<MenuItem key={item.value} value={item.value} onClick={item.action}> | ||
{item.label} | ||
</MenuItem> | ||
))} | ||
</Select> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters