Skip to content

Commit

Permalink
Merge pull request #8 from amansinghbais/6-create-product-store-flow
Browse files Browse the repository at this point in the history
Improved: routing flow for store creation, fixed timezone fetching issue, dynamic error message, helper text (#6)
  • Loading branch information
ymaheshwari1 authored May 31, 2024
2 parents d9e2470 + e1c108f commit 6b9050e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
6 changes: 5 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"Display current physical quantity expected at locations while inventory counting.": "Display current physical quantity expected at locations while inventory counting.",
"Edit": "Edit",
"facilities": "{count} facilities",
"facility": "{count} facility",
"Failed to create product store.": "Failed to create product store.",
"Failed to remove tag.": "Failed to remove tag.",
"Failed to update product store name.": "Failed to update product store name.",
Expand All @@ -46,7 +47,7 @@
"Go to OMS": "Go to OMS",
"Hold pre-order physical inventory": "Hold pre-order physical inventory",
"ID": "ID",
"Id prefix": "Id prefix",
"ID prefix": "ID prefix",
"Identifier": "Identifier",
"Import": "Import",
"Inventory": "Inventory",
Expand Down Expand Up @@ -85,6 +86,7 @@
"Product store created successfully.": "Product store created successfully.",
"Product store configurations updated successfully.": "Product store configurations updated successfully.",
"Product store ID cannot be more than 20 characters.": "Product store ID cannot be more than 20 characters.",
"Product store ID represents an unique ID for your product store": "Product store ID represents an unique ID for your product store",
"Product store name": "Product store name",
"Product store name can't be empty.": "Product store name can't be empty.",
"Product store name updated successfully.": "Product store name updated successfully.",
Expand All @@ -99,11 +101,13 @@
"Search time zones": "Search time zones",
"Soft Allocation": "Soft Allocation",
"Secondary identifier": "Secondary identifier",
"Select": "Select",
"Select operating countries": "Select operating countries",
"Select time zone": "Select time zone",
"Send notification to Shopify": "Send notification to Shopify",
"Settings": "Settings",
"Setup product store": "Setup product store",
"shipping method": "{count} shipping method",
"shipping methods": "{count} shipping methods",
"Shipment method": "Shipment method",
"Shipping facility tag": "Shipping facility tag",
Expand Down
6 changes: 5 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ const routes: Array<RouteRecordRaw> = [
{
path: "/add-configurations/:productStoreId",
name: "AddConfigurations",
component: AddConfigurations
component: AddConfigurations,
beforeEnter: (to, from, next) => {
if(from.path === "/create-product-store") next()
else router.push(from.path)
}
},
{
path: "/product-store-details/:productStoreId",
Expand Down
5 changes: 4 additions & 1 deletion src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ const getUserProfile = async (token: any): Promise<any> => {
}

const getAvailableTimeZones = async (): Promise <any> => {
return api({
const url = store.getters["user/getBaseUrl"]
const baseURL = url.startsWith('http') ? url.includes('/rest/s1/admin') ? url.replace("admin", "available-to-promise") : `${url}/rest/s1/available-to-promise/` : `https://${url}.hotwax.io/rest/s1/available-to-promise/`;
return client({
url: "user/getAvailableTimeZones",
method: "get",
baseURL,
cache: true
});
}
Expand Down
5 changes: 2 additions & 3 deletions src/views/AddConfigurations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ion-page>
<ion-header>
<ion-toolbar>
<ion-back-button default-href="/tabs/create-product-store" slot="start"></ion-back-button>
<ion-back-button default-href="/tabs/product-store" slot="start"></ion-back-button>
<ion-title>{{ translate("Add configurations") }}</ion-title>
<ion-buttons slot="end">
<ion-button slot="icon-only">
Expand Down Expand Up @@ -105,15 +105,14 @@ async function setupProductStore() {
const resp = await ProductStoreService.updateProductStore(payload);
if(!hasError(resp)) {
showToast(translate("Product store configurations updated successfully."))
router.push(`/product-store-details/${productStore.value.productStoreId}`);
router.replace(`/product-store-details/${productStore.value.productStoreId}`);
} else {
throw resp.data;
}
} catch(error: any) {
logger.error(error)
showToast(translate("Failed to add configurations to the product store."))
}
}
</script>

Expand Down
6 changes: 3 additions & 3 deletions src/views/CreateProductStore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ion-input>
</ion-item>
<ion-item lines="none">
<ion-input ref="storeId" v-model="formData.productStoreId" @ionChange="validateGroupId($event.detail.value)" @ionBlur="markGroupIdTouched" label-placement="floating" :label="translate('ID')" :errorText="translate('Product store ID cannot be more than 20 characters.')" :helper-text="translate('Product store represents a brand in OMS')" :clear-input="true" />
<ion-input ref="storeId" v-model="formData.productStoreId" @ionChange="validateGroupId($event.detail.value)" @ionBlur="markGroupIdTouched" label-placement="floating" :label="translate('ID')" :errorText="translate('Product store ID cannot be more than 20 characters.')" :helper-text="translate('Product store ID represents an unique ID for your product store')" :clear-input="true" />
</ion-item>

<ion-item v-if="!dbicCountriesCount">
Expand Down Expand Up @@ -126,12 +126,12 @@ async function manageConfigurations() {
}
showToast(translate("Product store created successfully."))
router.push(`add-configurations/${productStoreId}`);
router.replace(`add-configurations/${productStoreId}`);
} else {
throw resp.data;
}
} catch(error: any) {
showToast(translate("Failed to create product store."))
showToast(translate(error.response?.data?.errors ? error.response.data.errors : "Failed to create product store."))
logger.error(error);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/views/ProductStore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

<div class="tablet" @click.stop="">
<ion-chip outline>
<ion-label>{{ translate("facilities", { count: store.facilityCount }) }}</ion-label>
<ion-label>{{ translate(store.facilityCount > 1 ? "facilities" : "facility", { count: store.facilityCount }) }}</ion-label>
<ion-icon :icon="openOutline" color="primary"/>
</ion-chip>
</div>

<div class="tablet" @click.stop="">
<ion-chip outline>
<ion-label>{{ translate("shipping methods", { count: store.shipmentMethodCount }) }}</ion-label>
<ion-label>{{ translate(store.shipmentMethodCount > 1 ? "shipping methods" : "shipping method", { count: store.shipmentMethodCount }) }}</ion-label>
</ion-chip>
</div>
</div>
Expand Down
30 changes: 15 additions & 15 deletions src/views/ProductStoreDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</ion-item>

<ion-item>
<ion-icon :icon="thunderstormOutline" slot="start"/>
<ion-icon :icon="compassOutline" slot="start"/>
<ion-toggle :checked="getBooleanValue(productStore.enableBrokering)" @click.prevent="updateProductStoreDetail($event, 'enableBrokering', true)">{{ translate("Order brokering") }}</ion-toggle>
</ion-item>

Expand All @@ -52,7 +52,7 @@
</ion-item-divider>

<ion-item>
<ion-input :label="translate('Id prefix')" :placeholder="translate('prefix')" :value="productStore.orderNumberPrefix" @keydown.enter="updateProductStoreDetail($event, 'orderNumberPrefix', false)" />
<ion-input :label="translate('ID prefix')" :placeholder="translate('prefix')" :value="productStore.orderNumberPrefix" @keydown.enter="updateProductStoreDetail($event, 'orderNumberPrefix', false)" />
</ion-item>
<ion-item lines="none">
<ion-label>
Expand Down Expand Up @@ -245,7 +245,7 @@
</ion-item>

<ion-item>
<ion-select :label="translate('Pre-order group')" interface="popover" :value="settings['PRE_ORDER_GROUP_ID']?.settingValue" @ionChange="updateProductStoreSettings($event, 'PRE_ORDER_GROUP_ID', false)">
<ion-select :label="translate('Pre-order group')" interface="popover" :placeholder="translate('Select')" :value="settings['PRE_ORDER_GROUP_ID']?.settingValue" @ionChange="updateProductStoreSettings($event, 'PRE_ORDER_GROUP_ID', false)">
<ion-select-option v-for="group in facilityGroups" :key="group.facilityGroupId" :value="group.facilityGroupId">{{ group.facilityGroupName }}</ion-select-option>
</ion-select>
</ion-item>
Expand All @@ -268,7 +268,7 @@
</ion-item-divider>

<ion-item>
<ion-select :label="translate('Global identifier')" interface="popover" :value="productStore.productIdentifierEnumId" @ionChange="updateProductStoreDetail($event, 'productIdentifierEnumId', false)">
<ion-select :label="translate('Global identifier')" interface="popover" :placeholder="translate('Select')" :value="productStore.productIdentifierEnumId" @ionChange="updateProductStoreDetail($event, 'productIdentifierEnumId', false)">
<ion-select-option v-for="identifier in productIdentifiers" :key="identifier.enumId" :value="identifier.enumId">{{ identifier.description }}</ion-select-option>
</ion-select>
</ion-item>
Expand All @@ -283,13 +283,13 @@
</ion-item-divider>

<ion-item>
<ion-select :label="translate('Primary identifier')" interface="popover" :value="getPreferredIdentification('primaryId')" @ionChange="updatePreferredIdentification($event, 'primaryId')">
<ion-select :label="translate('Primary identifier')" interface="popover" :placeholder="translate('Select')" :value="getPreferredIdentification('primaryId')" @ionChange="updatePreferredIdentification($event, 'primaryId')">
<ion-select-option v-for="option in productIdentificationOptions" :key="option" :value="option">{{ option }}</ion-select-option>
</ion-select>
</ion-item>

<ion-item>
<ion-select :label="translate('Secondary identifier')" interface="popover" :value="getPreferredIdentification('secondaryId')" @ionChange="updatePreferredIdentification($event, 'secondaryId')">
<ion-select :label="translate('Secondary identifier')" interface="popover" :placeholder="translate('Select')" :value="getPreferredIdentification('secondaryId')" @ionChange="updatePreferredIdentification($event, 'secondaryId')">
<ion-select-option v-for="option in productIdentificationOptions" :key="option" :value="option">{{ option }}</ion-select-option>
</ion-select>
</ion-item>
Expand All @@ -316,7 +316,7 @@
</ion-item>

<ion-item>
<ion-select :label="translate('Shipment method')" interface="popover" :value="settings['RF_SHIP_MTHD']?.settingValue" @ionChange="updateProductStoreSettings($event, 'RF_SHIP_MTHD', false)" >
<ion-select :label="translate('Shipment method')" interface="popover" :placeholder="translate('Select')" :value="settings['RF_SHIP_MTHD']?.settingValue" @ionChange="updateProductStoreSettings($event, 'RF_SHIP_MTHD', false)" >
<ion-select-option v-for="shipmentMethod in shipmentMethodTypes" :key="shipmentMethod.shipmentMethodTypeId" :value="shipmentMethod.shipmentMethodTypeId">{{ shipmentMethod.description ? shipmentMethod.description : shipmentMethod.shipmentMethodTypeId }}</ion-select-option>
</ion-select>
</ion-item>
Expand Down Expand Up @@ -347,7 +347,7 @@

<script setup lang="ts">
import { IonBackButton, IonButton, IonCard, IonCardHeader, IonCardSubtitle, IonCardTitle, IonContent, IonChip, IonHeader, IonIcon, IonInput, IonItem, IonItemDivider, IonLabel, IonList, IonPage, IonSelect, IonSelectOption, IonTitle, IonToggle, IonToolbar, alertController, onIonViewWillEnter } from "@ionic/vue";
import { addCircleOutline, closeCircleOutline, mapOutline, thunderstormOutline, wineOutline } from "ionicons/icons";
import { addCircleOutline, closeCircleOutline, compassOutline, mapOutline, wineOutline } from "ionicons/icons";
import { translate } from "@/i18n";
import { useStore } from "vuex";
import { computed, defineProps, ref } from "vue";
Expand Down Expand Up @@ -437,15 +437,15 @@ async function renameProductStore() {
{
text: translate("Confirm"),
handler: async(data) => {
if(!data.storeName) {
if(!data.storeName.trim()) {
showToast(translate("Product store name can't be empty."));
return false;
}
if(data.storeName === productStore.value.storeName) return;
if(data.storeName.trim() === productStore.value.storeName) return;
const updatedStore = JSON.parse(JSON.stringify(productStore.value));
updatedStore.storeName = data.storeName;
updatedStore.storeName = data.storeName.trim();
try {
const resp = await ProductStoreService.updateProductStore(updatedStore);
Expand Down Expand Up @@ -482,23 +482,23 @@ async function createUpdateTag(enumId: string) {
{
text: settingEnums[enumId]?.settingValue ? translate("Update") : translate("Add"),
handler: async(data) => {
if(!data.tag) {
if(!data.tag.trim()) {
showToast(translate("Tags can't be empty."));
return false;
}
if(data.tag === settingEnums[enumId]?.settingValue) return;
if(data.tag.trim() === settingEnums[enumId]?.settingValue) return;
let payload;
if(settingEnums[enumId]?.productStoreId) {
payload = settingEnums[enumId];
payload.settingValue = data.tag;
payload.settingValue = data.tag.trim();
} else {
payload = {
fromDate: DateTime.now().toMillis(),
productStoreId: productStore.value.productStoreId,
settingTypeEnumId: enumId,
settingValue: data.tag
settingValue: data.tag.trim()
}
}
Expand Down

0 comments on commit 6b9050e

Please sign in to comment.