Skip to content

Commit 09aa213

Browse files
committed
Add ability to update the user's timezone
1 parent ebde11b commit 09aa213

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

api/pkg/requests/user_update_request.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package requests
22

33
import (
44
"strings"
5+
"time"
56

67
"github.com/google/uuid"
78

@@ -11,18 +12,25 @@ import (
1112
// UserUpdate is the payload for updating a phone
1213
type UserUpdate struct {
1314
request
15+
Timezone string `json:"timezone" example:"Europe/Helsinki"`
1416
ActivePhoneID string `json:"active_phone_id" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
1517
}
1618

1719
// Sanitize sets defaults to MessageOutstanding
1820
func (input *UserUpdate) Sanitize() UserUpdate {
1921
input.ActivePhoneID = strings.TrimSpace(input.ActivePhoneID)
22+
input.Timezone = strings.TrimSpace(input.Timezone)
2023
return *input
2124
}
2225

2326
// ToUpdateParams converts UserUpdate to services.UserUpdateParams
2427
func (input *UserUpdate) ToUpdateParams() services.UserUpdateParams {
28+
location, err := time.LoadLocation(input.Timezone)
29+
if err != nil {
30+
location = time.UTC
31+
}
2532
return services.UserUpdateParams{
2633
ActivePhoneID: uuid.MustParse(input.ActivePhoneID),
34+
Timezone: location,
2735
}
2836
}

api/pkg/services/user_service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (service *UserService) Get(ctx context.Context, authUser entities.AuthUser)
7171

7272
// UserUpdateParams are parameters for updating an entities.User
7373
type UserUpdateParams struct {
74+
Timezone *time.Location
7475
ActivePhoneID uuid.UUID
7576
}
7677

@@ -91,6 +92,7 @@ func (service *UserService) Update(ctx context.Context, authUser entities.AuthUs
9192
service.marketingService.AddToList(ctx, user)
9293
}
9394

95+
user.Timezone = params.Timezone.String()
9496
user.ActivePhoneID = &params.ActivePhoneID
9597

9698
if err = service.repository.Update(ctx, user); err != nil {

web/components/MessageThreadHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export default class MessageThreadHeader extends Vue {
210210
}
211211
212212
async onOwnerChanged(owner: string) {
213-
await this.$store.dispatch('setOwner', owner)
213+
await this.$store.dispatch('updateUser', { owner })
214214
if (this.$route.name !== 'threads') {
215215
await this.$store.dispatch('setThreadId', null)
216216
await this.$router.push({ name: 'threads' })

web/pages/settings/index.vue

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838
{{ mdiShieldCheck }}
3939
</v-icon>
4040
</h4>
41+
<v-autocomplete
42+
v-if="$store.getters.getUser"
43+
dense
44+
outlined
45+
:value="$store.getters.getUser.timezone"
46+
class="mx-auto mt-2"
47+
style="max-width: 250px"
48+
label="Timezone"
49+
:items="timezones"
50+
@change="updateUser"
51+
></v-autocomplete>
4152
</div>
4253
<h5 class="text-h4 mb-3 mt-3">API Key</h5>
4354
<p class="text--secondary">
@@ -654,10 +665,14 @@ export default Vue.extend({
654665
}
655666
return this.$store.getters.getUser.api_key
656667
},
668+
timezones() {
669+
return Intl.supportedValuesOf('timeZone')
670+
},
657671
},
658672
mounted() {
659673
this.$store.dispatch('clearAxiosError')
660674
this.$store.dispatch('loadUser')
675+
this.$store.dispatch('loadPhones')
661676
this.loadWebhooks()
662677
this.loadDiscordIntegrations()
663678
},
@@ -821,6 +836,27 @@ export default Vue.extend({
821836
})
822837
},
823838
839+
updateUser(timezone) {
840+
this.resetErrors()
841+
this.$store
842+
.dispatch('updateUser', {
843+
owner: this.$store.getters.getOwner,
844+
timezone,
845+
})
846+
.then(() => {
847+
this.$store.dispatch('addNotification', {
848+
message: 'Timezone updated successfully',
849+
type: 'success',
850+
})
851+
})
852+
.catch(() => {
853+
this.$store.dispatch('addNotification', {
854+
message: 'Failed to update timezone',
855+
type: 'error',
856+
})
857+
})
858+
},
859+
824860
updateWebhook() {
825861
this.resetErrors()
826862
this.updatingWebhook = true

web/store/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,10 @@ export const actions = {
510510
(x: Phone) => x.id === context.getters.getUser.active_phone_id
511511
)
512512
if (phone) {
513-
await context.dispatch('setOwner', phone.phone_number)
513+
await context.dispatch('updateUser', {
514+
owner: phone.phone_number,
515+
timezone: context.getters.getUser.timezone,
516+
})
514517
}
515518
}
516519
},
@@ -550,8 +553,11 @@ export const actions = {
550553
await context.commit('setAxiosError', null)
551554
},
552555

553-
async setOwner(context: ActionContext<State, State>, owner: string) {
554-
await context.commit('setOwner', owner)
556+
async updateUser(
557+
context: ActionContext<State, State>,
558+
payload: { owner: string; timezone: string }
559+
) {
560+
await context.commit('setOwner', payload.owner)
555561

556562
const phone = context.getters.getActivePhone as Phone | null
557563
if (!phone) {
@@ -560,6 +566,7 @@ export const actions = {
560566

561567
const response = await axios.put('/v1/users/me', {
562568
active_phone_id: phone.id,
569+
timezone: payload.timezone ?? context.getters.getUser.timezone,
563570
})
564571

565572
setApiKey(response.data.data.api_key)

0 commit comments

Comments
 (0)