Limit the use of the same shortcut name when adding a shortcut

Signed-off-by: AmbrishRamachandiran <ambrish.r@infosys.com>
This commit is contained in:
AmbrishRamachandiran
2023-07-26 11:28:41 +05:30
parent d37b9c5aee
commit ceee1c3ca2
2 changed files with 5 additions and 10 deletions
+2 -5
View File
@@ -61,20 +61,17 @@ export const AddShortcut = ({
const [formValues, setFormValues] = useState<FormValues>();
const open = Boolean(anchorEl);
const analytics = useAnalytics();
const shortcutData = api.get();
const handleSave: SubmitHandler<FormValues> = async ({ url, title }) => {
if (!api.get().some(shortcutTitle => shortcutTitle.title === title)) {
analytics.captureEvent('click', `Clicked 'Save' in AddShortcut`);
}
const shortcut: Omit<Shortcut, 'id'> = { url, title };
const shortcutData = api.get();
try {
if (shortcutData.some(shortcutTitle => shortcutTitle.title === title)) {
alertApi.post({
message: `Shortcut title already exist`,
severity: 'error',
});
throw new Error(`Shortcut Title '${title}' already Exist`);
} else {
await api.add(shortcut);
alertApi.post({
+3 -5
View File
@@ -60,6 +60,7 @@ export const EditShortcut = ({
const alertApi = useApi(alertApiRef);
const open = Boolean(anchorEl);
const analytics = useAnalytics();
const shortcutData = api.get();
const handleSave: SubmitHandler<FormValues> = async ({ url, title }) => {
if (!api.get().some(shortcutTitle => shortcutTitle.title === title)) {
@@ -72,11 +73,8 @@ export const EditShortcut = ({
};
try {
if (api.get().some(shortcutTitle => shortcutTitle.title === title)) {
alertApi.post({
message: `Shortcut title already exist`,
severity: 'error',
});
if (shortcutData.some(shortcutTitle => shortcutTitle.title === title)) {
throw new Error(`Shortcut Title '${title}' already Exist`);
} else {
await api.update(newShortcut);
alertApi.post({