Skip to content

Commit 9ce5f60

Browse files
committed
Fix widget business hours showing wrong time due to missing UTC offset
1 parent d0a3527 commit 9ce5f60

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

cmd/chat.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type chatSettingsResponse struct {
6767
livechat.Config
6868
BusinessHours []bhmodels.BusinessHours `json:"business_hours,omitempty"`
6969
DefaultBusinessHoursID int `json:"default_business_hours_id,omitempty"`
70+
WorkingHoursUTCOffset *int `json:"working_hours_utc_offset,omitempty"`
7071
CustomAttributes map[int]customAttributeWidget `json:"custom_attributes,omitempty"`
7172
}
7273

@@ -113,7 +114,7 @@ func handleGetChatSettings(r *fastglue.Request) error {
113114
response.BusinessHours = businessHours
114115
}
115116

116-
// Get default business hours ID from general settings which is the default / fallback.
117+
// Get default business hours ID and UTC offset from general settings.
117118
out, err := app.setting.GetByPrefix("app")
118119
if err != nil {
119120
app.lo.Error("error fetching general settings", "error", err)
@@ -123,6 +124,13 @@ func handleGetChatSettings(r *fastglue.Request) error {
123124
if bhID, ok := settings["app.business_hours_id"].(string); ok {
124125
response.DefaultBusinessHoursID, _ = strconv.Atoi(bhID)
125126
}
127+
if tz, ok := settings["app.timezone"].(string); ok && tz != "" {
128+
if loc, err := time.LoadLocation(tz); err == nil {
129+
_, offset := time.Now().In(loc).Zone()
130+
offsetMinutes := offset / 60
131+
response.WorkingHoursUTCOffset = &offsetMinutes
132+
}
133+
}
126134
}
127135
}
128136
}
@@ -712,7 +720,6 @@ func saveContactAttrsAndCollectConvoAttrs(app *App, contactID int, claims *Claim
712720
return mergeCustomAttributes(jwtConvoAttrs, formConvoAttrs)
713721
}
714722

715-
716723
// resolveOrCreateExternalContact finds or creates a contact from JWT claims.
717724
// It tries: 1) lookup by external_user_id, 2) create new (which internally enriches by email if possible).
718725
// On every call it syncs name/email from JWT claims.

frontend/apps/widget/src/components/ChatTitle.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const businessHoursStatus = computed(() => {
7575
return null
7676
}
7777
78-
const utcOffset = conversation.working_hours_utc_offset || 0
78+
const utcOffset = conversation.working_hours_utc_offset ?? config.working_hours_utc_offset ?? 0
7979
const withinHoursMessage = config.chat_reply_expectation_message || ''
8080
8181
const { status, isWithin } = getBusinessHoursStatus(businessHours, utcOffset, withinHoursMessage)

frontend/apps/widget/src/components/NoticeBanner.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="border rounded-lg p-4" v-if="noticeText" role="status">
3-
<div class="flex items-start gap-3">
4-
<AlertTriangle class="flex-shrink-0 mt-1" size="16" />
3+
<div class="flex items-center justify-center gap-3">
4+
<AlertTriangle class="flex-shrink-0" size="16" />
55
<p class="text-sm">{{ noticeText }}</p>
66
</div>
77
</div>

internal/conversation/conversation.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,22 +1761,26 @@ func (m *Manager) calculateBusinessHoursInfo(conversation models.Conversation) (
17611761
}
17621762
}
17631763

1764-
// Fallback to general settings if no team business hours
1765-
if businessHoursID == nil {
1764+
// Fallback to general settings if no team business hours or no timezone
1765+
if businessHoursID == nil || timezone == "" {
17661766
out, err := m.settingsStore.GetByPrefix("app")
17671767
if err == nil {
17681768
var settings map[string]any
17691769
err := json.Unmarshal([]byte(out), &settings)
17701770
if err != nil {
17711771
m.lo.Error("error unmarshalling settings", "error", err)
17721772
} else {
1773-
if bhIDStr, ok := settings["app.business_hours_id"].(string); ok && bhIDStr != "" {
1774-
if bhID, err := strconv.Atoi(bhIDStr); err == nil {
1775-
businessHoursID = &bhID
1773+
if businessHoursID == nil {
1774+
if bhIDStr, ok := settings["app.business_hours_id"].(string); ok && bhIDStr != "" {
1775+
if bhID, err := strconv.Atoi(bhIDStr); err == nil {
1776+
businessHoursID = &bhID
1777+
}
17761778
}
17771779
}
1778-
if tz, ok := settings["app.timezone"].(string); ok {
1779-
timezone = tz
1780+
if timezone == "" {
1781+
if tz, ok := settings["app.timezone"].(string); ok {
1782+
timezone = tz
1783+
}
17801784
}
17811785
}
17821786
}

0 commit comments

Comments
 (0)