Skip to content

Commit 20777e4

Browse files
committed
refactor(dav): remove timezone from AvailabilitiyForm
It is handled in personal settings now. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent ac545cc commit 20777e4

File tree

1 file changed

+69
-103
lines changed

1 file changed

+69
-103
lines changed

apps/dav/src/components/AvailabilityForm.vue

Lines changed: 69 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,36 @@
44
-->
55
<template>
66
<div>
7-
<div class="time-zone">
8-
<label :for="`vs${timeZonePickerId}__combobox`" class="time-zone__heading">
9-
{{ $t('dav', 'Time zone:') }}
10-
</label>
11-
<span class="time-zone-text">
12-
<NcTimezonePicker v-model="timezone" :uid="timeZonePickerId" />
13-
</span>
14-
</div>
15-
167
<CalendarAvailability :slots.sync="slots"
178
:loading="loading"
18-
:l10n-to="$t('dav', 'to')"
19-
:l10n-delete-slot="$t('dav', 'Delete slot')"
20-
:l10n-empty-day="$t('dav', 'No working hours set')"
21-
:l10n-add-slot="$t('dav', 'Add slot')"
22-
:l10n-week-day-list-label="$t('dav', 'Weekdays')"
23-
:l10n-monday="$t('dav', 'Monday')"
24-
:l10n-tuesday="$t('dav', 'Tuesday')"
25-
:l10n-wednesday="$t('dav', 'Wednesday')"
26-
:l10n-thursday="$t('dav', 'Thursday')"
27-
:l10n-friday="$t('dav', 'Friday')"
28-
:l10n-saturday="$t('dav', 'Saturday')"
29-
:l10n-sunday="$t('dav', 'Sunday')"
30-
:l10n-start-picker-label="(dayName) => $t('dav', 'Pick a start time for {dayName}', { dayName })"
31-
:l10n-end-picker-label="(dayName) => $t('dav', 'Pick a end time for {dayName}', { dayName })" />
32-
33-
<NcCheckboxRadioSwitch :checked.sync="automated">
34-
{{ $t('dav', 'Automatically set user status to "Do not disturb" outside of availability to mute all notifications.') }}
9+
:l10n-to="t('dav', 'to')"
10+
:l10n-delete-slot="t('dav', 'Delete slot')"
11+
:l10n-empty-day="t('dav', 'No working hours set')"
12+
:l10n-add-slot="t('dav', 'Add slot')"
13+
:l10n-week-day-list-label="t('dav', 'Weekdays')"
14+
:l10n-monday="t('dav', 'Monday')"
15+
:l10n-tuesday="t('dav', 'Tuesday')"
16+
:l10n-wednesday="t('dav', 'Wednesday')"
17+
:l10n-thursday="t('dav', 'Thursday')"
18+
:l10n-friday="t('dav', 'Friday')"
19+
:l10n-saturday="t('dav', 'Saturday')"
20+
:l10n-sunday="t('dav', 'Sunday')"
21+
:l10n-start-picker-label="(dayName) => t('dav', 'Pick a start time for {dayName}', { dayName })"
22+
:l10n-end-picker-label="(dayName) => t('dav', 'Pick a end time for {dayName}', { dayName })" />
23+
24+
<NcCheckboxRadioSwitch v-model="automated">
25+
{{ t('dav', 'Automatically set user status to "Do not disturb" outside of availability to mute all notifications.') }}
3526
</NcCheckboxRadioSwitch>
3627

3728
<NcButton :disabled="loading || saving"
38-
type="primary"
29+
variant="primary"
3930
@click="save">
40-
{{ $t('dav', 'Save') }}
31+
{{ t('dav', 'Save') }}
4132
</NcButton>
4233
</div>
4334
</template>
4435

45-
<script>
36+
<script setup lang="ts">
4637
import { CalendarAvailability } from '@nextcloud/calendar-availability-vue'
4738
import { loadState } from '@nextcloud/initial-state'
4839
import {
@@ -60,77 +51,57 @@ import {
6051
} from '../service/PreferenceService.js'
6152
import NcButton from '@nextcloud/vue/components/NcButton'
6253
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
63-
import NcTimezonePicker from '@nextcloud/vue/components/NcTimezonePicker'
64-
65-
export default {
66-
name: 'AvailabilityForm',
67-
components: {
68-
NcButton,
69-
NcCheckboxRadioSwitch,
70-
CalendarAvailability,
71-
NcTimezonePicker,
72-
},
73-
data() {
74-
// Try to determine the current timezone, and fall back to UTC otherwise
75-
const defaultTimezoneId = (new Intl.DateTimeFormat())?.resolvedOptions()?.timeZone ?? 'UTC'
76-
77-
return {
78-
loading: true,
79-
saving: false,
80-
timezone: defaultTimezoneId,
81-
slots: getEmptySlots(),
82-
automated: loadState('dav', 'user_status_automation') === 'yes',
54+
import { getCapabilities } from '@nextcloud/capabilities'
55+
import { onMounted, ref } from 'vue'
56+
import logger from '../service/logger.js'
57+
import { t } from '@nextcloud/l10n'
58+
59+
// @ts-expect-error capabilities is missing the capability to type it...
60+
const timezone = getCapabilities().core.user?.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone
61+
62+
const loading = ref(true)
63+
const saving = ref(false)
64+
const slots = ref(getEmptySlots())
65+
const automated = ref(loadState('dav', 'user_status_automation') === 'yes')
66+
67+
onMounted(async () => {
68+
try {
69+
const slotData = await findScheduleInboxAvailability()
70+
if (!slotData) {
71+
logger.debug('no availability is set')
72+
} else {
73+
slots.value = slotData.slots
74+
logger.debug('availability loaded', { slots: slots.value })
8375
}
84-
},
85-
computed: {
86-
timeZonePickerId() {
87-
return `tz-${(Math.random() + 1).toString(36).substring(7)}`
88-
},
89-
},
90-
async mounted() {
91-
try {
92-
const slotData = await findScheduleInboxAvailability()
93-
if (!slotData) {
94-
console.info('no availability is set')
95-
this.slots = getEmptySlots()
96-
} else {
97-
const { slots, timezoneId } = slotData
98-
this.slots = slots
99-
if (timezoneId) {
100-
this.timezone = timezoneId
101-
}
102-
console.info('availability loaded', this.slots, this.timezoneId)
103-
}
104-
} catch (e) {
105-
console.error('could not load existing availability', e)
106-
107-
showError(t('dav', 'Failed to load availability'))
108-
} finally {
109-
this.loading = false
76+
} catch (error) {
77+
logger.error('could not load existing availability', { error })
78+
showError(t('dav', 'Failed to load availability'))
79+
} finally {
80+
loading.value = false
81+
}
82+
})
83+
84+
/**
85+
* Save current slots on the server
86+
*/
87+
async function save() {
88+
saving.value = true
89+
try {
90+
await saveScheduleInboxAvailability(slots.value, timezone)
91+
if (automated.value) {
92+
await enableUserStatusAutomation()
93+
} else {
94+
await disableUserStatusAutomation()
11095
}
111-
},
112-
methods: {
113-
async save() {
114-
try {
115-
this.saving = true
116-
117-
await saveScheduleInboxAvailability(this.slots, this.timezone)
118-
if (this.automated) {
119-
await enableUserStatusAutomation()
120-
} else {
121-
await disableUserStatusAutomation()
122-
}
123-
124-
showSuccess(t('dav', 'Saved availability'))
125-
} catch (e) {
126-
console.error('could not save availability', e)
127-
128-
showError(t('dav', 'Failed to save availability'))
129-
} finally {
130-
this.saving = false
131-
}
132-
},
133-
},
96+
97+
showSuccess(t('dav', 'Saved availability'))
98+
} catch (e) {
99+
console.error('could not save availability', e)
100+
101+
showError(t('dav', 'Failed to save availability'))
102+
} finally {
103+
saving.value = false
104+
}
134105
}
135106
</script>
136107

@@ -165,11 +136,6 @@ export default {
165136
width: 97px;
166137
}
167138
168-
:deep(.multiselect) {
169-
border: 1px solid var(--color-border-dark);
170-
width: 120px;
171-
}
172-
173139
.time-zone {
174140
padding-block: 32px 12px;
175141
padding-inline: 0 12px;

0 commit comments

Comments
 (0)