From b4502fd9d8bb8baf97746752ef7da469cba86506 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Mon, 1 Aug 2022 14:15:56 +0530 Subject: [PATCH] refactor(gui-v2): replace callback with promise Signed-off-by: Pranav C --- .../composables/useColumnCreateStore.ts | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/nc-gui-v2/composables/useColumnCreateStore.ts b/packages/nc-gui-v2/composables/useColumnCreateStore.ts index c90f79338c..a51296e17c 100644 --- a/packages/nc-gui-v2/composables/useColumnCreateStore.ts +++ b/packages/nc-gui-v2/composables/useColumnCreateStore.ts @@ -47,20 +47,21 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState }, // validation for unique column name { - validator: (rule: any, value: any, callback: (errMsg?: string) => void) => { - if ( - meta.value?.columns?.some( - (c) => - c.id !== formState.value.id && // ignore current column - // compare against column_name and title - ((value || '').toLowerCase() === (c.column_name || '').toLowerCase() || - (value || '').toLowerCase() === (c.title || '').toLowerCase()), - ) - ) { - callback('Duplicate column name') - } - - callback() + validator: (rule: any, value: any) => { + return new Promise((resolve, reject) => { + if ( + meta.value?.columns?.some( + (c) => + c.id !== formState.value.id && // ignore current column + // compare against column_name and title + ((value || '').toLowerCase() === (c.column_name || '').toLowerCase() || + (value || '').toLowerCase() === (c.title || '').toLowerCase()), + ) + ) { + return reject(new Error('Duplicate column name')) + } + resolve() + }) }, }, ],