Skip to content

Commit 6e1167a

Browse files
authored
Merge pull request #632 from ymaheshwari1/fix/timeZone
Fixed: timeZone does not gets updated for user login, removed confirm alert, and added loading state
2 parents 2b9fc83 + a6c355a commit 6e1167a

File tree

4 files changed

+66
-52
lines changed

4 files changed

+66
-52
lines changed

src/locales/en.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"App": "App",
1818
"Approve orders": "Approve orders",
1919
"Archived": "Archived",
20-
"Are you sure you want to change the time zone to?": "Are you sure you want to change the time zone to {timeZoneId}?",
2120
"Are you sure you want to save these changes?": "Are you sure you want to save these changes?",
2221
"Are you sure you want to schedule these jobs?": "Are you sure you want to schedule these jobs?",
2322
"Authenticating": "Authenticating",
@@ -58,7 +57,6 @@
5857
"Close": "Close",
5958
"Completed orders": "Completed orders",
6059
"Configuration missing": "Configuration missing",
61-
"Confirm": "Confirm",
6260
"Copied job details to clipboard": "Copied job details to clipboard",
6361
"Copy details": "Copy details",
6462
"Custom": "Custom",
@@ -88,6 +86,7 @@
8886
"Every day": "Every day",
8987
"Failed": "Failed",
9088
"Failed to schedule service(s)": "Failed to schedule {count} service(s)",
89+
"Fetching TimeZones": "Fetching TimeZones",
9190
"File upload status": "File upload status",
9291
"Filters": "Filters",
9392
"Finished": "Finished",
@@ -290,7 +289,6 @@
290289
"Update orders": "Update orders",
291290
"Update promise date": "Update promise date",
292291
"Update shipping dates in Shopify": "Update shipping dates in Shopify",
293-
"Update time zone": "Update time zone",
294292
"Upload": "Upload",
295293
"Upload Pending Process": "Upload Pending Process",
296294
"Use POs to manage catalog": "Use POs to manage catalog",

src/store/modules/user/actions.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ const actions: ActionTree<UserState, RootState> = {
165165
/**
166166
* Update user timeZone
167167
*/
168-
async setUserTimeZone ( { state, commit }, payload) {
168+
async setUserTimeZone({ state, commit }, payload) {
169169
const current: any = state.current;
170170
// if set the same timezone again, no API call should happen
171-
if(current.userTimeZone !== payload.timeZoneId) {
171+
if(current.userTimeZone !== payload.tzId) {
172172
const resp = await UserService.setUserTimeZone(payload)
173173
if (resp.status === 200 && !hasError(resp)) {
174-
current.userTimeZone = payload.timeZoneId;
174+
current.userTimeZone = payload.tzId;
175175
commit(types.USER_INFO_UPDATED, current);
176176
Settings.defaultZone = current.userTimeZone;
177177
showToast(translate("Time zone updated successfully"));

src/theme/variables.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,23 @@ aside {
275275
--border-radius: 8px;
276276
}
277277

278+
.empty-state {
279+
max-width: 100%;
280+
display: flex;
281+
flex-direction: column;
282+
align-items: center;
283+
justify-content: center;
284+
padding: 10px;
285+
}
286+
287+
.empty-state > img {
288+
object-fit: contain;
289+
}
290+
291+
.empty-state > p {
292+
text-align: center;
293+
}
294+
278295
@media (min-width: 991px) {
279296
main {
280297
display: flex;

src/views/TimezoneModal.vue

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,33 @@
1414
</ion-header>
1515

1616
<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>
2122

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 -->
3442
<ion-fab vertical="bottom" horizontal="end" slot="fixed">
35-
<ion-fab-button :disabled="!timeZoneId" @click="saveAlert">
43+
<ion-fab-button :disabled="!timeZoneId" @click="setUserTimeZone">
3644
<ion-icon :icon="saveOutline" />
3745
</ion-fab-button>
3846
</ion-fab>
@@ -54,16 +62,18 @@ import {
5462
IonRadioGroup,
5563
IonRadio,
5664
IonSearchbar,
65+
IonSpinner,
5766
IonTitle,
5867
IonToolbar,
5968
modalController,
60-
alertController } from "@ionic/vue";
69+
} from "@ionic/vue";
6170
import { defineComponent } from "vue";
6271
import { closeOutline, saveOutline } from "ionicons/icons";
6372
import { useStore } from "@/store";
6473
import { UserService } from "@/services/UserService";
6574
import { hasError } from '@/utils'
6675
import { DateTime } from 'luxon';
76+
import logger from "@/logger";
6777
6878
export default defineComponent({
6979
name: "TimeZoneModal",
@@ -81,6 +91,7 @@ export default defineComponent({
8191
IonRadioGroup,
8292
IonRadio,
8393
IonSearchbar,
94+
IonSpinner,
8495
IonTitle,
8596
IonToolbar
8697
},
@@ -89,32 +100,14 @@ export default defineComponent({
89100
queryString: '',
90101
filteredTimeZones: [],
91102
timeZones: [],
92-
timeZoneId: ''
103+
timeZoneId: '',
104+
isLoading: false
93105
}
94106
},
95107
methods: {
96108
closeModal() {
97109
modalController.dismiss({ dismissed: true });
98110
},
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-
},
118111
preventSpecialCharacters($event: any) {
119112
// Searching special characters fails the API, hence, they must be omitted
120113
if(/[`!@#$%^&*()_+\-=\\|,.<>?~]/.test($event.key)) $event.preventDefault();
@@ -126,22 +119,28 @@ export default defineComponent({
126119
});
127120
},
128121
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)
136134
}
135+
this.isLoading = false;
137136
},
138137
async selectSearchBarText(event: any) {
139138
const element = await event.target.getInputElement()
140139
element.select();
141140
},
142141
async setUserTimeZone() {
143142
await this.store.dispatch("user/setUserTimeZone", {
144-
"timeZoneId": this.timeZoneId
143+
"tzId": this.timeZoneId
145144
})
146145
this.closeModal()
147146
}

0 commit comments

Comments
 (0)