14
14
</ion-header >
15
15
16
16
<ion-content class =" ion-padding" >
17
- <!-- Empty state -->
18
- <div class =" empty-state" v-if =" filteredTimeZones.length === 0" >
19
- <p >{{ $t("No time zone found")}}</p >
20
- </div >
17
+ <form @keyup.enter =" setUserTimeZone" >
18
+ <div class =" empty-state" v-if =" isLoading" >
19
+ <ion-spinner name =" crescent" />
20
+ <p >{{ $t("Fetching TimeZones")}}</p >
21
+ </div >
21
22
22
- <!-- Timezones -->
23
- <div v-else >
24
- <ion-list >
25
- <ion-radio-group value =" rd" v-model =" timeZoneId" >
26
- <ion-item :key =" timeZone.id" v-for =" timeZone in filteredTimeZones" >
27
- <ion-label >{{ timeZone.label }} ({{ timeZone.id }})</ion-label >
28
- <ion-radio :value =" timeZone.id" slot =" start" />
29
- </ion-item >
30
- </ion-radio-group >
31
- </ion-list >
32
- </div >
33
-
23
+ <!-- Empty state -->
24
+ <div class =" empty-state" v-else-if =" filteredTimeZones.length === 0" >
25
+ <p >{{ $t("No time zone found")}}</p >
26
+ </div >
27
+
28
+ <!-- Timezones -->
29
+ <div v-else >
30
+ <ion-list >
31
+ <ion-radio-group value =" rd" v-model =" timeZoneId" >
32
+ <ion-item :key =" timeZone.id" v-for =" timeZone in filteredTimeZones" >
33
+ <ion-label >{{ timeZone.label }} ({{ timeZone.id }})</ion-label >
34
+ <ion-radio :value =" timeZone.id" slot =" start" />
35
+ </ion-item >
36
+ </ion-radio-group >
37
+ </ion-list >
38
+ </div >
39
+ </form >
40
+
41
+ <!-- Defined ion-fab outside of form element as the fab button losoe its styling when wrapped inside form -->
34
42
<ion-fab vertical =" bottom" horizontal =" end" slot =" fixed" >
35
- <ion-fab-button :disabled =" !timeZoneId" @click =" saveAlert " >
43
+ <ion-fab-button :disabled =" !timeZoneId" @click =" setUserTimeZone " >
36
44
<ion-icon :icon =" saveOutline" />
37
45
</ion-fab-button >
38
46
</ion-fab >
@@ -54,16 +62,18 @@ import {
54
62
IonRadioGroup ,
55
63
IonRadio ,
56
64
IonSearchbar ,
65
+ IonSpinner ,
57
66
IonTitle ,
58
67
IonToolbar ,
59
68
modalController ,
60
- alertController } from " @ionic/vue" ;
69
+ } from " @ionic/vue" ;
61
70
import { defineComponent } from " vue" ;
62
71
import { closeOutline , saveOutline } from " ionicons/icons" ;
63
72
import { useStore } from " @/store" ;
64
73
import { UserService } from " @/services/UserService" ;
65
74
import { hasError } from ' @/utils'
66
75
import { DateTime } from ' luxon' ;
76
+ import logger from " @/logger" ;
67
77
68
78
export default defineComponent ({
69
79
name: " TimeZoneModal" ,
@@ -81,6 +91,7 @@ export default defineComponent({
81
91
IonRadioGroup ,
82
92
IonRadio ,
83
93
IonSearchbar ,
94
+ IonSpinner ,
84
95
IonTitle ,
85
96
IonToolbar
86
97
},
@@ -89,32 +100,14 @@ export default defineComponent({
89
100
queryString: ' ' ,
90
101
filteredTimeZones: [],
91
102
timeZones: [],
92
- timeZoneId: ' '
103
+ timeZoneId: ' ' ,
104
+ isLoading: false
93
105
}
94
106
},
95
107
methods: {
96
108
closeModal() {
97
109
modalController .dismiss ({ dismissed: true });
98
110
},
99
- async saveAlert() {
100
- const message = this .$t (" Are you sure you want to change the time zone to?" , { timeZoneId: this .timeZoneId });
101
- const alert = await alertController .create ({
102
- header: this .$t (" Update time zone" ),
103
- message ,
104
- buttons: [
105
- {
106
- text: this .$t (" Cancel" ),
107
- },
108
- {
109
- text: this .$t (" Confirm" ),
110
- handler : () => {
111
- this .setUserTimeZone ();
112
- }
113
- }
114
- ],
115
- });
116
- return alert .present ();
117
- },
118
111
preventSpecialCharacters($event : any ) {
119
112
// Searching special characters fails the API, hence, they must be omitted
120
113
if (/ [`!@#$%^&*()_+\-= \\ |,. <>?~] / .test ($event .key )) $event .preventDefault ();
@@ -126,22 +119,28 @@ export default defineComponent({
126
119
});
127
120
},
128
121
async getAvailableTimeZones() {
129
- const resp = await UserService .getAvailableTimeZones ()
130
- if (resp .status === 200 && ! hasError (resp )) {
131
- // We are filtering valid the timeZones coming with response here
132
- this .timeZones = resp .data .filter ((timeZone : any ) => {
133
- return DateTime .local ().setZone (timeZone .id ).isValid ;
134
- });
135
- this .findTimeZone ();
122
+ this .isLoading = true ;
123
+ try {
124
+ const resp = await UserService .getAvailableTimeZones ()
125
+ if (resp .status === 200 && ! hasError (resp )) {
126
+ // We are filtering valid the timeZones coming with response here
127
+ this .timeZones = resp .data .filter ((timeZone : any ) => {
128
+ return DateTime .local ().setZone (timeZone .id ).isValid ;
129
+ });
130
+ this .findTimeZone ();
131
+ }
132
+ } catch (err ) {
133
+ logger .error (err )
136
134
}
135
+ this .isLoading = false ;
137
136
},
138
137
async selectSearchBarText(event : any ) {
139
138
const element = await event .target .getInputElement ()
140
139
element .select ();
141
140
},
142
141
async setUserTimeZone() {
143
142
await this .store .dispatch (" user/setUserTimeZone" , {
144
- " timeZoneId " : this .timeZoneId
143
+ " tzId " : this .timeZoneId
145
144
})
146
145
this .closeModal ()
147
146
}
0 commit comments