|
|
@ -1,4 +1,3 @@ |
|
|
|
import type { Dayjs } from 'dayjs' |
|
|
|
|
|
|
|
import dayjs from 'dayjs' |
|
|
|
import dayjs from 'dayjs' |
|
|
|
import { defineNuxtPlugin } from '#app' |
|
|
|
import { defineNuxtPlugin } from '#app' |
|
|
|
|
|
|
|
|
|
|
@ -8,9 +7,18 @@ const handleFeedbackForm = async () => { |
|
|
|
|
|
|
|
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
const { $api } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
|
|
const fetchFeedbackForm = async (now: Dayjs) => { |
|
|
|
const isFirstTimePolling = !currentFeedbackForm.lastFormPollDate |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const now = dayjs() |
|
|
|
|
|
|
|
const lastFormPolledDate = dayjs(currentFeedbackForm.lastFormPollDate) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isFirstTimePolling || dayjs.duration(now.diff(lastFormPolledDate)).days() > 0) { |
|
|
|
|
|
|
|
$api.instance |
|
|
|
|
|
|
|
.get('/api/v1/feedback_form') |
|
|
|
|
|
|
|
.then((response) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const { data: feedbackForm } = await $api.instance.get('/api/v1/feedback_form') |
|
|
|
const { data: feedbackForm } = response |
|
|
|
|
|
|
|
if (!feedbackForm.error) { |
|
|
|
const isFetchedFormDuplicate = currentFeedbackForm.url === feedbackForm.url |
|
|
|
const isFetchedFormDuplicate = currentFeedbackForm.url === feedbackForm.url |
|
|
|
|
|
|
|
|
|
|
|
currentFeedbackForm = { |
|
|
|
currentFeedbackForm = { |
|
|
@ -19,21 +27,13 @@ const handleFeedbackForm = async () => { |
|
|
|
createdAt: feedbackForm.created_at, |
|
|
|
createdAt: feedbackForm.created_at, |
|
|
|
isHidden: isFetchedFormDuplicate ? currentFeedbackForm.isHidden : false, |
|
|
|
isHidden: isFetchedFormDuplicate ? currentFeedbackForm.isHidden : false, |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
console.error(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) {} |
|
|
|
const isFirstTimePolling = !currentFeedbackForm.lastFormPollDate |
|
|
|
}) |
|
|
|
|
|
|
|
.catch(() => {}) |
|
|
|
const now = dayjs() |
|
|
|
|
|
|
|
const lastFormPolledDate = dayjs(currentFeedbackForm.lastFormPollDate) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isFirstTimePolling || dayjs.duration(now.diff(lastFormPolledDate)).days() > 0) { |
|
|
|
|
|
|
|
await fetchFeedbackForm(now) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default defineNuxtPlugin(async () => { |
|
|
|
export default defineNuxtPlugin(() => { |
|
|
|
await handleFeedbackForm() |
|
|
|
handleFeedbackForm() |
|
|
|
}) |
|
|
|
}) |
|
|
|