diff --git a/src/components/CreateMappingModal.vue b/src/components/CreateMappingModal.vue index 58c4255..56313c6 100644 --- a/src/components/CreateMappingModal.vue +++ b/src/components/CreateMappingModal.vue @@ -121,18 +121,12 @@ export default defineComponent({ showToast(translate("Map all fields")); return } - const id = this.generateUniqueMappingPrefId(); - await this.store.dispatch("user/createFieldMapping", { id, name: this.mappingName, value: this.fieldMapping, mappingType: this.mappingType }) - this.closeModal(id); + const mappingPrefId = await this.store.dispatch("user/createFieldMapping", { name: this.mappingName, value: this.fieldMapping, mappingType: this.mappingType }) + this.closeModal(mappingPrefId); }, areAllFieldsSelected() { return Object.values(this.fieldMapping).every(field => field !== ""); }, - //Todo: Generating unique identifiers as we are currently storing in local storage. Need to remove it as we will be storing data on server. - generateUniqueMappingPrefId(): any { - const id = Math.floor(Math.random() * 1000); - return !this.fieldMappings[id] ? id : this.generateUniqueMappingPrefId(); - } }, setup() { const store = useStore(); diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index fdc070f..d576428 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -219,13 +219,13 @@ const actions: ActionTree = { }, async createFieldMapping({ commit }, payload) { + let mappingPrefId = '' try { const mappingTypes = JSON.parse(process.env.VUE_APP_MAPPING_TYPES as string) const mappingPrefTypeEnumId = mappingTypes[payload.mappingType]; const params = { - mappingPrefId: payload.id, mappingPrefName: payload.name, mappingPrefValue: JSON.stringify(payload.value), mappingPrefTypeEnumId @@ -237,8 +237,9 @@ const actions: ActionTree = { // using id coming from server, as the random generated id sent in payload is not set as mapping id // and an auto generated mapping from server is set as id + mappingPrefId = resp.data.mappingPrefId const fieldMapping = { - id: resp.data.mappingPrefId, + id: mappingPrefId, name: payload.name, value: payload.value, type: payload.mappingType @@ -254,6 +255,7 @@ const actions: ActionTree = { logger.error('error', err) showToast(translate('Failed to save CSV mapping.')) } + return mappingPrefId; }, async updateFieldMapping({ commit, state }, payload) {