mirror of https://github.com/nocodb/nocodb
5 changed files with 68 additions and 2 deletions
@ -0,0 +1,5 @@
|
||||
export default { |
||||
url: 'https://docs.google.com/forms/d/e/1FAIpQLSeTlAfZjszgr53lArz3NvUEnJGOT9JtG9NAU5d0oQwunDS2Pw/viewform?embedded=true', |
||||
createdAt: new Date('2020-01-01T00:00:00.000Z').toISOString(), |
||||
isHidden: false, |
||||
} |
@ -0,0 +1,46 @@
|
||||
import type { Dayjs } from 'dayjs' |
||||
import dayjs from 'dayjs' |
||||
import duration from 'dayjs/plugin/duration' |
||||
import { defineNuxtPlugin } from '#app' |
||||
|
||||
dayjs.extend(duration) |
||||
|
||||
const handleFeedbackForm = async () => { |
||||
let { feedbackForm: currentFeedbackForm } = $(useGlobalState()) |
||||
if (!currentFeedbackForm) return |
||||
|
||||
const { $api } = useNuxtApp() |
||||
|
||||
const fetchFeedbackForm = async (now: Dayjs) => { |
||||
try { |
||||
const { data: feedbackForm } = await $api.instance.get('/api/v1/feedback_form') |
||||
const isFetchedFormDuplicate = currentFeedbackForm.url === feedbackForm.url |
||||
|
||||
currentFeedbackForm = { |
||||
url: feedbackForm.url, |
||||
lastFormPollDate: now.toISOString(), |
||||
createdAt: feedbackForm.created_at, |
||||
isHidden: isFetchedFormDuplicate ? currentFeedbackForm.isHidden : false, |
||||
} |
||||
} catch (e) { |
||||
console.error(e) |
||||
} |
||||
} |
||||
|
||||
const isFirstTimePolling = !currentFeedbackForm.lastFormPollDate |
||||
|
||||
const now = dayjs() |
||||
const lastFormPolledDate = dayjs(currentFeedbackForm.lastFormPollDate) |
||||
|
||||
if (isFirstTimePolling || dayjs.duration(now.diff(lastFormPolledDate)).days() > 0) { |
||||
await fetchFeedbackForm(now) |
||||
} |
||||
} |
||||
|
||||
const handleInitFunctions = async () => { |
||||
await handleFeedbackForm() |
||||
} |
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => { |
||||
nuxtApp.vueApp.use(handleInitFunctions) |
||||
}) |
Loading…
Reference in new issue