Files
chatwoot/app/javascript/dashboard/components/CustomSnoozeModal.vue
T
Vishnu Narayanan 2762da5636 feat: Add dynamic 'Last snoozed' option with reactive updates
- Add 'UNTIL_LAST_CUSTOM_TIME' snooze option that shows saved custom time
- Implement smart expiration: times expire when passed OR after 7 days
- Add user-friendly format: 'Sat, 23 Aug, 8.16pm'
- Fix caching issue: actions now update dynamically without page refresh
- Auto-save custom times to localStorage for quick reuse
- Add reactive event system for real-time UI updates
- Include option filtering to show/hide based on saved time availability

Improves UX by allowing users to quickly reuse their last custom snooze time
without having to re-enter it every time.
2025-08-22 18:41:18 +05:30

86 lines
2.2 KiB
Vue

<script>
import DatePicker from 'vue-datepicker-next';
import NextButton from 'dashboard/components-next/button/Button.vue';
import { getUnixTime } from 'date-fns';
import { saveLastCustomSnoozeTime } from 'dashboard/helper/customSnoozeStorage';
export default {
components: {
DatePicker,
NextButton,
},
emits: ['close', 'chooseTime'],
data() {
return {
snoozeTime: null,
lang: {
days: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
yearFormat: 'YYYY',
monthFormat: 'MMMM',
},
};
},
methods: {
onClose() {
this.$emit('close');
},
chooseTime() {
if (this.snoozeTime) {
const unixTimestamp = getUnixTime(this.snoozeTime);
// Save the custom time to localStorage for future use
saveLastCustomSnoozeTime(unixTimestamp);
// The saveLastCustomSnoozeTime function will emit the event automatically
this.$emit('chooseTime', this.snoozeTime);
}
},
disabledDate(date) {
// Disable all the previous dates
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
return date < yesterday;
},
disabledTime(date) {
// Allow only time after 1 hour
const now = new Date();
now.setHours(now.getHours() + 1);
return date < now;
},
},
};
</script>
<template>
<div class="flex flex-col">
<woot-modal-header :header-title="$t('CONVERSATION.CUSTOM_SNOOZE.TITLE')" />
<form
class="modal-content w-full pt-2 px-5 pb-6"
@submit.prevent="chooseTime"
>
<DatePicker
v-model:value="snoozeTime"
type="datetime"
inline
input-class="mx-input "
:lang="lang"
:disabled-date="disabledDate"
:disabled-time="disabledTime"
/>
<div class="flex flex-row justify-end w-full gap-2 px-0 py-2">
<NextButton
faded
slate
type="reset"
:label="$t('CONVERSATION.CUSTOM_SNOOZE.CANCEL')"
@click.prevent="onClose"
/>
<NextButton
type="submit"
:label="$t('CONVERSATION.CUSTOM_SNOOZE.APPLY')"
/>
</div>
</form>
</div>
</template>