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 10:17:53 +05:30
parent 5d99ca9350
commit d37b9c5aee
2 changed files with 21 additions and 9 deletions
+5 -2
View File
@@ -63,11 +63,14 @@ export const AddShortcut = ({
const analytics = useAnalytics();
const handleSave: SubmitHandler<FormValues> = async ({ url, title }) => {
analytics.captureEvent('click', `Clicked 'Save' in AddShortcut`);
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 (api.get().some(shortcutTitle => shortcutTitle.title === title)) {
if (shortcutData.some(shortcutTitle => shortcutTitle.title === title)) {
alertApi.post({
message: `Shortcut title already exist`,
severity: 'error',
+16 -7
View File
@@ -62,7 +62,9 @@ export const EditShortcut = ({
const analytics = useAnalytics();
const handleSave: SubmitHandler<FormValues> = async ({ url, title }) => {
analytics.captureEvent('click', `Clicked 'Save' in Edit Shortcut`);
if (!api.get().some(shortcutTitle => shortcutTitle.title === title)) {
analytics.captureEvent('click', `Clicked 'Save' in Edit Shortcut`);
}
const newShortcut: Shortcut = {
...shortcut,
url,
@@ -70,12 +72,19 @@ export const EditShortcut = ({
};
try {
await api.update(newShortcut);
alertApi.post({
message: `Updated shortcut '${title}'`,
severity: 'success',
display: 'transient',
});
if (api.get().some(shortcutTitle => shortcutTitle.title === title)) {
alertApi.post({
message: `Shortcut title already exist`,
severity: 'error',
});
} else {
await api.update(newShortcut);
alertApi.post({
message: `Updated shortcut '${title}'`,
severity: 'success',
display: 'transient',
});
}
} catch (error) {
alertApi.post({
message: `Could not update shortcut: ${error.message}`,