Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: Spinner in Timezone Model for Timezone Configuration (#210) #249

Merged
merged 13 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"Make sure you've reviewed the products and their counts before uploading them for review": "Make sure you've reviewed the products and their counts before uploading them for review",
"No results found": "No results found",
"No time zone found": "No time zone found",
"Fetching time zones":"Fetching time zones",
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
"Ok": "Ok",
"OMS": "OMS",
"OMS instance": "OMS instance",
Expand Down
83 changes: 53 additions & 30 deletions src/views/TimezoneModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,60 @@
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button @click="closeModal">
<ion-button @click="closeModal">
<ion-icon :icon="close" />
</ion-button>
</ion-buttons>
<ion-title>{{ $t("Select time zone") }}</ion-title>
</ion-toolbar>
<ion-toolbar>
<ion-searchbar @ionFocus="selectSearchBarText($event)" :placeholder="$t('Search time zones')" v-model="queryString" @keyup.enter="queryString = $event.target.value; findTimeZone()" @keydown="preventSpecialCharacters($event)" />
<ion-searchbar @ionFocus="selectSearchBarText($event)" :placeholder="$t('Search time zones')" v-model="queryString"
@keyup.enter="queryString = $event.target.value; findTimeZone()" @keydown="preventSpecialCharacters($event)" />
</ion-toolbar>
</ion-header>



<ion-content class="ion-padding">
<!-- Empty state -->
<div class="empty-state" v-if="filteredTimeZones.length === 0">
<p>{{ $t("No time zone found")}}</p>
<div>
<div class="empty-state" v-if="loading && timeZones.length === 0">
<ion-item lines="none" color="none">

<ion-spinner class="center-spinner" color="secondary" name="crescent" slot="start" ></ion-spinner>
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
{{ $t("Fetching time zones") }}
</ion-item>
</div>
</div>

<div v-if="!loading && filteredTimeZones.length === 0">
<div class="empty-state">
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
<p>{{ $t("No time zone found") }}</p>
</div>
</div>

<!-- Timezones -->
<div v-else>
<ion-list>
<ion-radio-group value="rd" v-model="timeZoneId">
<ion-item :key="timeZone.id" v-for="timeZone in filteredTimeZones">
<ion-radio justify="start" label-placement="end" :value="timeZone.id">{{ timeZone.label }} ({{ timeZone.id }})</ion-radio>
<ion-radio justify="start" label-placement="end" :value="timeZone.id">{{ timeZone.label }} ({{ timeZone.id
}})</ion-radio>
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
</ion-item>
</ion-radio-group>
</ion-list>
</div>



<ion-fab vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button :disabled="!timeZoneId" @click="saveAlert">
<ion-icon :icon="save" />
</ion-fab-button>
</ion-fab>
</ion-content>
</template>

<script lang="ts">
import {
</template>


<script lang="ts">
import {
IonButtons,
IonButton,
IonContent,
Expand All @@ -55,17 +71,19 @@ import {
IonTitle,
IonToolbar,
modalController,
alertController } from "@ionic/vue";
import { defineComponent } from "vue";
import { close, save } from "ionicons/icons";
import { useStore } from "@/store";
import { UserService } from "@/services/UserService";
import { hasError } from '@/utils'
import { DateTime } from 'luxon';

export default defineComponent({
alertController
} from "@ionic/vue";
import { defineComponent } from "vue";
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
import { close, save } from "ionicons/icons";
import { useStore } from "@/store";
import { UserService } from "@/services/UserService";
import { hasError } from '@/utils'
import { DateTime } from 'luxon';


export default defineComponent({
name: "TimeZoneModal",
components: {
components: {
IonButtons,
IonButton,
IonContent,
Expand All @@ -79,14 +97,15 @@ export default defineComponent({
IonRadio,
IonSearchbar,
IonTitle,
IonToolbar
IonToolbar
},
data() {
return {
queryString: '',
filteredTimeZones: [],
timeZones: [],
timeZoneId: ''
timeZoneId: '',
loading: true
}
},
methods: {
Expand Down Expand Up @@ -114,23 +133,26 @@ export default defineComponent({
},
preventSpecialCharacters($event: any) {
// Searching special characters fails the API, hence, they must be omitted
if(/[`!@#$%^&*()_+\-=\\|,.<>?~]/.test($event.key)) $event.preventDefault();
if (/[`!@#$%^&*()_+\-=\\|,.<>?~]/.test($event.key)) $event.preventDefault();
},
findTimeZone() {
findTimeZone() {
const queryString = this.queryString.toLowerCase();
this.filteredTimeZones = this.timeZones.filter((timeZone: any) => {
return timeZone.id.toLowerCase().match(queryString) || timeZone.label.toLowerCase().match(queryString);
});
},
async getAvailableTimeZones() {
const resp = await UserService.getAvailableTimeZones()
if(resp.status === 200 && !hasError(resp)) {
console.log(resp);
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved

if (resp.status === 200 && !hasError(resp)) {
// We are filtering valid the timeZones coming with response here
this.timeZones = resp.data.filter((timeZone: any) => {
return DateTime.local().setZone(timeZone.id).isValid;
});
this.findTimeZone();
}
this.loading = false;
},
async selectSearchBarText(event: any) {
const element = await event.target.getInputElement()
Expand All @@ -143,7 +165,7 @@ export default defineComponent({
this.closeModal()
}
},
beforeMount () {
beforeMount() {
this.getAvailableTimeZones();
},
setup() {
Expand All @@ -154,5 +176,6 @@ export default defineComponent({
store
};
}
});
</script>
});
</script>

Loading