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:
@@ -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({
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user