-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): duplicate schedule warning (#295)
* fix(ui): duplicate schedule warning * fix(ui): duplicate schedule warning * fix(ui): duplicate schedules * fix(ui): schedule limit loophole refactored * fix(ui): schedule bypass hooks * fix(ui): useEnforceScheduleLimit hook created * fix(ui): added useCallback to hook * fix(ui): updated jsdoc comment on hook * fix(ui): updated jsdoc comments on hook
- Loading branch information
Showing
4 changed files
with
66 additions
and
27 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
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,45 @@ | ||
import useSchedules from '@views/hooks/useSchedules'; | ||
import React, { useCallback } from 'react'; | ||
|
||
import { Button } from '../components/common/Button'; | ||
import { usePrompt } from '../components/common/DialogProvider/DialogProvider'; | ||
|
||
const SCHEDULE_LIMIT = 10; | ||
|
||
/** | ||
* Hook that creates a function that enforces a maximum amount of schedules | ||
* | ||
* If a new schedule can be created without exceeding the limit, the function returns true | ||
* Otherwise, display a prompt explaining the limit, and returns false | ||
* | ||
* @returns a function, () => boolean | ||
*/ | ||
export function useEnforceScheduleLimit(): () => boolean { | ||
const [, schedules] = useSchedules(); | ||
const showDialog = usePrompt(); | ||
|
||
return useCallback(() => { | ||
if (schedules.length >= SCHEDULE_LIMIT) { | ||
showDialog({ | ||
title: `You have ${SCHEDULE_LIMIT} active schedules!`, | ||
|
||
description: ( | ||
<> | ||
To encourage organization,{' '} | ||
<span className='text-ut-burntorange'>please consider removing some unused schedules</span> you | ||
may have. | ||
</> | ||
), | ||
|
||
buttons: close => ( | ||
<Button variant='filled' color='ut-burntorange' onClick={close}> | ||
I Understand | ||
</Button> | ||
), | ||
}); | ||
|
||
return false; | ||
} | ||
return true; | ||
}, [schedules, showDialog]); | ||
} |