feat: allow bypassing the 10-schedule limit (#675)
* feat: allow bypassing the 10-schedule limit * feat: option to bypass 10 schedules- code done, not tested * feat(ui): option to bypass 10 schedules * feat(ui): button to lead to settings after reaching max limit * Delete manifest.json * Remove cross-env from build:watch script * Remove cross-env and update caniuse-lite version Removed cross-env dependency and updated caniuse-lite version. * chore: lint --------- Co-authored-by: Derek <derex1987@gmail.com>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { background } from '@shared/messages';
|
||||
import { OptionsStore } from '@shared/storage/OptionsStore';
|
||||
import { CRX_PAGES } from '@shared/types/CRXPages';
|
||||
import useSchedules from '@views/hooks/useSchedules';
|
||||
import React, { useCallback } from 'react';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { Button } from '../components/common/Button';
|
||||
import { usePrompt } from '../components/common/DialogProvider/DialogProvider';
|
||||
@@ -17,8 +20,33 @@ const SCHEDULE_LIMIT = 10;
|
||||
export function useEnforceScheduleLimit(): () => boolean {
|
||||
const [, schedules] = useSchedules();
|
||||
const showDialog = usePrompt();
|
||||
const [allowMoreSchedules, setAllowMoreSchedules] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
(async () => {
|
||||
try {
|
||||
const val = await OptionsStore.get('allowMoreSchedules');
|
||||
if (mounted) setAllowMoreSchedules(val ?? false);
|
||||
} catch (err) {
|
||||
console.error('Failed to read allowMoreSchedules from OptionsStore:', err);
|
||||
}
|
||||
})();
|
||||
|
||||
const listener = OptionsStore.listen('allowMoreSchedules', async ({ newValue }) => {
|
||||
setAllowMoreSchedules(newValue);
|
||||
});
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
OptionsStore.removeListener(listener);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return useCallback(() => {
|
||||
// If user has enabled bypass, allow creating more schedules
|
||||
if (allowMoreSchedules) return true;
|
||||
|
||||
if (schedules.length >= SCHEDULE_LIMIT) {
|
||||
showDialog({
|
||||
title: `You have too many schedules!`,
|
||||
@@ -27,19 +55,33 @@ export function useEnforceScheduleLimit(): () => boolean {
|
||||
<>
|
||||
To encourage organization,{' '}
|
||||
<span className='text-ut-burntorange'>please consider deleting any unused schedules</span> you
|
||||
may have.
|
||||
may have. You can increase the limit in the settings if it’s really necessary.
|
||||
</>
|
||||
),
|
||||
|
||||
buttons: close => (
|
||||
<Button variant='filled' color='ut-burntorange' onClick={close}>
|
||||
I understand
|
||||
</Button>
|
||||
<>
|
||||
<Button
|
||||
variant='outline'
|
||||
color='ut-black'
|
||||
onClick={() => {
|
||||
close();
|
||||
// open options/settings page so user can enable bypass if they are advising staff
|
||||
const url = chrome.runtime.getURL(CRX_PAGES.OPTIONS);
|
||||
background.openNewTab({ url });
|
||||
}}
|
||||
>
|
||||
Open Settings
|
||||
</Button>
|
||||
<Button variant='filled' color='ut-burntorange' onClick={close}>
|
||||
I understand
|
||||
</Button>
|
||||
</>
|
||||
),
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, [schedules, showDialog]);
|
||||
}, [schedules, showDialog, allowMoreSchedules]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user