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:
@@ -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',
|
||||
|
||||
@@ -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}`,
|
||||
|
||||
Reference in New Issue
Block a user