π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix(nc-gui): move onboarding flow in oss files
Ramesh Maneeec887513ef2
diff --git a/packages/nc-gui/components/auth/onboarding/Layout/ImagePreviewSection.vue b/packages/nc-gui/components/auth/onboarding/Layout/ImagePreviewSection.vuenew file mode 100644index 0000000000..020038200f--- /dev/null+++ b/packages/nc-gui/components/auth/onboarding/Layout/ImagePreviewSection.vue@@ -0,0 +1,149 @@+<script lang="ts" setup>+import gridImage from '~/assets/img/views/grid-with-sidebar.png'+import galleryImage from '~/assets/img/views/gallery-with-sidebar.png'+import kanbanImage from '~/assets/img/views/kanban-with-sidebar.png'+import calendarImage from '~/assets/img/views/calendar-with-sidebar.png'++import moscotWelcomeOrange from '~/assets/img/moscot/welcome-orange.png'+import moscotWelcomeGreen from '~/assets/img/moscot/welcome-green.png'+import moscotWelcomePurple from '~/assets/img/moscot/welcome-purple.png'++import moscotCollaboration from '~/assets/img/moscot/collabe.png'++import moscotGridTableOrange from '~/assets/img/moscot/grid-table-orange.png'+import moscotGridTableBrand from '~/assets/img/moscot/grid-table-brand.png'++const { questions, lastVisibleQuestionIndex, formState } = useOnboardingFlow()++const currentQuestion = computed(() => questions.value[lastVisibleQuestionIndex.value]!)++/**+ * Next question is used to preload images to avoid flickering+ */+const nextQuestion = computed(() => questions.value[lastVisibleQuestionIndex.value + 1])++const getRightSectionInfo = (question: OnboardingQuestionType): OnboardingRightSectionType => {+ if (!question || !question.rightSection) {+ return {+ themeColor: 'orange',+ moscot: 'moscotWelcomeOrange',+ imageName: 'grid',+ }+ }++ return ncIsFunction(question.rightSection) ? question.rightSection(formState.value) : question.rightSection+}++const rightSectionInfo = computed<OnboardingRightSectionType>(() => {+ return getRightSectionInfo(currentQuestion.value)+})++const nextQuestionRightSectionInfo = computed<OnboardingRightSectionType | undefined>(() => {+ return nextQuestion.value ? getRightSectionInfo(nextQuestion.value) : undefined+})++const bgColorClass = computed(() => {+ return onboardingFlowColoursMapping[rightSectionInfo.value.themeColor || 'orange']?.lightBg+})++const getMoscotImage = (moscot: OnboardingRightSectionType['moscot']) => {+ switch (moscot) {+ case 'moscotWelcomeGreen':+ return moscotWelcomeGreen+ case 'moscotWelcomePurple':+ return moscotWelcomePurple+ case 'moscotCollaboration':+ return moscotCollaboration+ case 'moscotGridTableBrand':+ return moscotGridTableBrand+ case 'moscotGridTableOrange':+ return moscotGridTableOrange+ default:+ return moscotWelcomeOrange+ }+}++const moscotImage = computed(() => {+ return getMoscotImage(rightSectionInfo.value.moscot)+})++const nextQuestionMoscotImage = computed(() => {+ return nextQuestionRightSectionInfo.value ? getMoscotImage(nextQuestionRightSectionInfo.value.moscot) : undefined+})++const moscotImageSize = computed(() => {+ switch (rightSectionInfo.value.moscot) {+ case 'moscotCollaboration':+ return {+ height: '311px',+ width: '536px',+ }+ case 'moscotGridTableBrand':+ case 'moscotGridTableOrange':+ return {+ height: '358px',+ width: '480px',+ }+ default:+ return {+ height: '233px',+ width: '263px',+ }+ }+})++const getViewImage = (imageName: OnboardingRightSectionType['imageName']) => {+ switch (imageName) {+ case 'grid':+ return gridImage+ case 'gallery':+ return galleryImage+ case 'kanban':+ return kanbanImage+ case 'calendar':+ return calendarImage+ default:+ return gridImage+ }+}++const viewImage = computed(() => {+ return getViewImage(rightSectionInfo.value.imageName)+})++const nextQuestionViewImage = computed(() => {+ return nextQuestionRightSectionInfo.value ? getViewImage(nextQuestionRightSectionInfo.value.imageName) : undefined+})+</script>++<template>+ <div class="flex flex-col items-center justify-center h-full relative" :class="[bgColorClass]">+ <div class="nc-view-image-box" :style="{ backgroundImage: `url(${viewImage})` }"></div>+ <div class="nc-view-image-box nc-moscot-image-box">+ <div class="h-full w-full relative">+ <img alt="moscot image" :src="moscotImage" class="nc-moscot-image" :style="moscotImageSize" />+ </div>+ </div>+ <div class="hidden">+ <!-- Pre-render images to avoid flickering -->+ <img v-if="nextQuestionMoscotImage" alt="prerender moscot image" :src="nextQuestionMoscotImage" />+ <img v-if="nextQuestionViewImage" alt="prerender view image" :src="nextQuestionViewImage" />+ </div>+ </div>+</template>++<style lang="scss" scoped>+.nc-view-image-box {+ @apply border border-nc-border-gray-medium bg-cover bg-no-repeat overflow-hidden rounded-lg absolute left-[240px] top-[50%] transform -translate-y-1/2 h-[min(760px,80%)] w-[1351px];+ box-shadow: 0 0 12px 4px rgba(0, 0, 0, 0.08);++ &.nc-moscot-image-box {+ @apply overflow-visible;+ box-shadow: none;++ .nc-moscot-image {+ @apply absolute -left-[184px] -bottom-[50px] object-contain;+ }+ }+}+</style>diff --git a/packages/nc-gui/components/auth/onboarding/Layout/index.vue b/packages/nc-gui/components/auth/onboarding/Layout/index.vuenew file mode 100644index 0000000000..8626f23679--- /dev/null+++ b/packages/nc-gui/components/auth/onboarding/Layout/index.vue@@ -0,0 +1,92 @@+<script lang="ts" setup>+const { stepper, onCompleteOnboardingFlow, isFilledQuestionAnswer, isFilledVisibleOptions, questionsMap } = useOnboardingFlow()++const { index: stepIndex, steps, isLast, isFirst, goToNext, goToPrevious } = stepper++const isFilledSecondScreenOptions = computed(() => {+ return questionsMap.value[2] ? isFilledQuestionAnswer(questionsMap.value[2]) : false+})++const progress = computed(() => {+ return {+ percentage: ((stepIndex.value + (isFilledVisibleOptions.value ? 1 : 0)) / steps.value.length) * 100,+ text: `${stepIndex.value + 1} / ${steps.value.length}`,+ }+})+</script>++<template>+ <div class="w-full flex items-stretch h-full">+ <div class="w-full lg:(w-1/2) transition-width duration-250 h-full flex flex-col gap-[120px] nc-scrollbar-thin relative">+ <header+ class="px-4 pt-6 lg:(pt-12 px-8) flex items-center justify-between w-full max-w-[672px] lg:max-w-[704px] mx-auto sticky top-0 lg:-top-4 bg-white"+ >+ <GeneralIcon icon="nocodb1" class="w-12 h-12 flex-none" />++ <div class="w-[200px] text-bodyBold pr-1">+ <a-progress+ :percent="progress.percentage"+ size="small"+ status="normal"+ stroke-color="#3366FF"+ trail-color="#F0F3FF"+ :format="() => progress.text"+ />+ </div>+ </header>+ <div class="flex-1 w-full max-w-[672px] lg:max-w-[704px] mx-auto flex flex-col gap-[120px] px-4 lg:(px-8)">+ <slot name="content"></slot>+ </div>++ <slot name="footer">+ <footer+ class="flex flex-col justify-end w-full max-w-[672px] lg:max-w-[704px] mx-auto px-4 pb-6 lg:(pb-12 px-8) sticky bottom-0 bg-white"+ >+ <div+ class="flex items-center"+ :class="{+ 'justify-center': stepIndex === 0 && !isFilledSecondScreenOptions,+ 'justify-between': stepIndex > 0 || isFilledSecondScreenOptions,+ }"+ >+ <NcButton v-if="stepIndex === 0" type="text" size="small" @click="onCompleteOnboardingFlow(true)">+ <div class="opacity-50">+ {{ $t('general.skip') }}+ </div>+ </NcButton>+ <NcButton v-else type="text" size="small" :disabled="isFirst" @click="goToPrevious()">+ <template #icon>+ <GeneralIcon icon="ncArrowLeft" class="w-4 h-4" />+ </template>+ {{ $t('general.back') }}+ </NcButton>+ <template v-if="stepIndex !== 0 || isFilledSecondScreenOptions">+ <NcButton+ v-if="!isLast"+ type="primary"+ size="small"+ :disabled="isLast || !isFilledVisibleOptions"+ @click="goToNext()"+ >+ <div class="flex items-center gap-2">+ {{ $t('labels.next') }}+ <div class="h-full rounded px-1 py-0.5">+ <GeneralIcon icon="ncEnter" class="w-4 h-4" />+ </div>+ </div>+ </NcButton>+ <div v-else></div>+ </template>+ </div>+ </footer>+ </slot>+ </div>+ <div class="hidden lg:block w-1/2 border-l">+ <slot name="imagePreviewSection">+ <AuthOnboardingLayoutImagePreviewSection />+ </slot>+ </div>+ </div>+</template>++<style lang="scss" scoped></style>diff --git a/packages/nc-gui/components/auth/onboarding/Question/Option/Icon.vue b/packages/nc-gui/components/auth/onboarding/Question/Option/Icon.vuenew file mode 100644index 0000000000..8641c3004c--- /dev/null+++ b/packages/nc-gui/components/auth/onboarding/Question/Option/Icon.vue@@ -0,0 +1,50 @@+<script lang="ts" setup>+interface Props {+ option: OnboardingOptionType+ iconSize?: OnboardingQuestionType['iconSize']+}++const props = withDefaults(defineProps<Props>(), {})++const { option, iconSize } = toRefs(props)++const showIconMapIcon = computed(() => {+ return (!option.value.iconType || option.value.iconType === 'iconMap') && option.value.icon+})++const shouldShowIcon = computed(() => {+ return option.value.iconType || (!option.value.iconType && option.value.icon)+})++const iconColor = computed(() => {+ return option.value.iconColor ? onboardingFlowColoursMapping[option.value.iconColor]?.content ?? '' : ''+})++const bgColorClass = computed(() => {+ return option.value.iconColor ? onboardingFlowColoursMapping[option.value.iconColor]?.lightBg ?? '' : ''+})+</script>++<template>+ <div v-if="shouldShowIcon">+ <div+ v-if="showIconMapIcon"+ class="flex items-center justify-center"+ :class="[+ bgColorClass,+ {+ 'rounded-lg': bgColorClass,+ },+ ]"+ :style="{+ width: `${iconSize?.width ?? 24}px`,+ height: `${iconSize?.height ?? 24}px`,+ }"+ >+ <GeneralIcon :icon="option.icon!" class="flex-none" :class="iconColor" />+ </div>+ <div></div>+ </div>+</template>++<style lang="scss" scoped></style>diff --git a/packages/nc-gui/components/auth/onboarding/Question/Option/index.vue b/packages/nc-gui/components/auth/onboarding/Question/Option/index.vuenew file mode 100644index 0000000000..9a70187441--- /dev/null+++ b/packages/nc-gui/components/auth/onboarding/Question/Option/index.vue@@ -0,0 +1,48 @@+<script lang="ts" setup>+interface Props {+ option: OnboardingOptionType+ iconSize?: OnboardingQuestionType['iconSize']+}++const props = withDefaults(defineProps<Props>(), {})++const { option } = toRefs(props)+</script>++<template>+ <div+ class="nc-onboarding-option"+ :class="{+ '!px-2 !rounded-xl': option.iconColor,+ }"+ >+ <AuthOnboardingQuestionOptionIcon :option="option" :icon-size="iconSize" />+ <div v-if="option.description" class="flex flex-col gap-1">+ <div class="text-bodyDefaultSmBold text-nc-content-gray-subtle">+ {{ option.value }}+ </div>+ <div class="text-bodyDefaultSm text-nc-content-gray-subtle2">+ {{ option.description }}+ </div>+ </div>+ <div v-else class="text-bodyBold text-nc-content-gray">+ {{ option.value }}+ </div>+ </div>+</template>++<style lang="scss" scoped>+.nc-onboarding-option {+ @apply flex items-center gap-2.5 px-3 py-2 border-1 border-nc-border-gray-medium rounded-lg cursor-pointer select-none transition-all duration-250;++ box-shadow: 0 0 4px 0 rgba(0, 0, 0, 0.08);++ &:hover:not(.nc-selected) {+ @apply bg-nc-bg-gray-extralight;+ }++ &.nc-selected {+ @apply border-nc-border-brand bg-nc-bg-brand !shadow-selected;+ }+}+</style>diff --git a/packages/nc-gui/components/auth/onboarding/Question/index.vue b/packages/nc-gui/components/auth/onboarding/Question/index.vuenew file mode 100644index 0000000000..34abd189ec--- /dev/null+++ b/packages/nc-gui/components/auth/onboarding/Question/index.vue@@ -0,0 +1,53 @@+<script lang="ts" setup>+interface Props {+ question: OnboardingQuestionType+ questionIndex: number+}++const props = withDefaults(defineProps<Props>(), {})++const { question, questionIndex } = toRefs(props)++const { questionsMap, formState, onSelectOption, stepper, lastVisibleQuestionIndex } = useOnboardingFlow()++const options = computed(() => {+ if (ncIsFunction(question.value.options)) {+ return question.value.options(formState.value) || []+ }++ return question.value.options || []+})++const anyOptionHasIcon = computed(() => {+ return options.value.some((option) => option.iconType || (!option.iconType && option.icon))+})++const isOptionSelected = (option: OnboardingOptionType) => {+ if (question.value.inputType === 'singleSelect') {+ return formState.value[question.value.id] === option.value+ }++ if (question.value.inputType === 'multiSelect') {+ return ((formState.value[question.value.id] || []) as string[]).includes(option.value)+ }+}+</script>++<template>+ <div class="flex flex-col gap-6">+ <h3 class="my-0 text-heading3 text-nc-content-gray-emphasis">{{ question.question }}</h3>+ <div class="flex flex-wrap gap-4 children:(w-[calc(50%-8px)] flex-none)">+ <template v-for="option of options" :key="option.value">+ <AuthOnboardingQuestionOption+ :option="option"+ :icon-size="question.iconSize"+ @click="onSelectOption(option, question, questionIndex)"+ :class="{+ '!justify-center': !anyOptionHasIcon,+ 'nc-selected': isOptionSelected(option),+ }"+ />+ </template>+ </div>+ </div>+</template>diff --git a/packages/nc-gui/components/auth/onboarding/index.vue b/packages/nc-gui/components/auth/onboarding/index.vuenew file mode 100644index 0000000000..67acc93a32--- /dev/null+++ b/packages/nc-gui/components/auth/onboarding/index.vue@@ -0,0 +1,45 @@+<script lang="ts" setup>+import type { VNodeRef } from '@vue/runtime-core'++const { onInitOnboardingFlow, visibleQuestions, stepper } = useOnboardingFlow()++const autoScrollQuestionRefs = ref<HTMLDivElement>()++const onSelectRef: VNodeRef = (el) => {+ if (el) {+ autoScrollQuestionRefs.value = (el as any)?.$el as HTMLDivElement+ }+}++let timer: any+watch(+ [() => visibleQuestions.value.length, () => stepper.index.value],+ ([newValue, newStepperIndex], [oldValue, oldStepperIndex], cleanup) => {+ if (newValue !== 2 || oldValue !== 1 || newStepperIndex !== oldStepperIndex) return++ timer = setTimeout(() => {+ autoScrollQuestionRefs.value?.scrollIntoView({ behavior: 'smooth' })+ }, 300)++ cleanup(() => {+ clearTimeout(timer)+ })+ },+)++onMounted(() => {+ onInitOnboardingFlow()+})+</script>++<template>+ <AuthOnboardingLayout>+ <template #content>+ <template v-for="(question, index) of visibleQuestions" :key="question.id">+ <AuthOnboardingQuestion :question="question" :question-index="index" :ref="onSelectRef" />+ </template>+ </template>+ </AuthOnboardingLayout>+</template>++<style lang="scss" scoped></style>diff --git a/packages/nc-gui/composables/useBetaFeatureToggle.ts b/packages/nc-gui/composables/useBetaFeatureToggle.tsindex 954910bb21..8b483f642f 100644--- a/packages/nc-gui/composables/useBetaFeatureToggle.ts+++ b/packages/nc-gui/composables/useBetaFeatureToggle.ts@@ -187,9 +187,8 @@ const FEATURES = [id: 'signup_onboarding_flow',title: 'Signup Onboarding Flow',description: 'Allows user to onboarding flow on signup.',- enabled: false,- version: 1,- isEE: true,+ enabled: true,+ version: 2,},] as constdiff --git a/packages/nc-gui/composables/useOnboardingFlow.ts b/packages/nc-gui/composables/useOnboardingFlow.tsnew file mode 100644index 0000000000..e31b9ee77a--- /dev/null+++ b/packages/nc-gui/composables/useOnboardingFlow.ts@@ -0,0 +1,510 @@+export interface OnboardingOptionType {+ value: string+ description?: string+ icon?: IconMapKey+ iconColor?: string+ /**+ * `Undefined` will be considered as `iconMap`+ */+ iconType?: 'indexedStepProgressBar' | 'iconMap'+ /**+ * `resetOnSelect` will be helpful if option is `None of the above` or `Other` to reset previous selection if user select this option+ */+ resetOnSelect?: boolean+}++export interface OnboardingRightSectionType {+ themeColor?: 'brand' | 'orange' | 'green' | 'purple' | 'pink'+ moscot?:+ | 'moscotWelcomeGreen'+ | 'moscotWelcomeOrange'+ | 'moscotWelcomePurple'+ | 'moscotCollaboration'+ | 'moscotGridTableBrand'+ | 'moscotGridTableOrange'+ imageName?: 'grid' | 'gallery' | 'calendar' | 'kanban'+}++export interface OnboardingQuestionType {+ id: number+ question: string+ inputType: 'singleSelect' | 'multiSelect'+ /**+ * MinSelection to auto navigate to next question if it is multiSelect input type+ */+ minSelection?: number+ options?: OnboardingOptionType[] | ((state?: { [questionId: string]: string | string[] }) => OnboardingOptionType[])+ rightSection: OnboardingRightSectionType | ((state?: { [questionId: string]: string | string[] }) => OnboardingRightSectionType)+ iconSize?: {+ width: number+ height: number+ }+}++export const useOnboardingFlow = createSharedComposable(() => {+ const { $e } = useNuxtApp()++ const router = useRouter()++ const route = router.currentRoute++ const { isFeatureEnabled } = useBetaFeatureToggle()++ const isEnabledOnboardingFlow = computed(() => {+ return isFeatureEnabled(FEATURE_FLAG.SIGNUP_ONBOARDING_FLOW)+ })++ /**+ * If true, the onboarding flow will be shown in home page - `/`+ */+ const showOnboardingFlowLocalState = ref(false)++ const showOnboardingFlow = computed(() => {+ return isEnabledOnboardingFlow.value && showOnboardingFlowLocalState.value && route.value.name === 'index'+ })++ // Timestamp when the onboarding flow is started+ const startedAt = ref()++ const formState = ref<{ [questionId: string]: string | string[] }>({})++ const questions = computed<OnboardingQuestionType[]>(() => {+ return [+ {+ id: 1,+ question: 'Hey! What do you plan on using NocoDB for?',+ inputType: 'singleSelect',+ options: [+ {+ value: 'Work',+ icon: 'ncBriefcase',+ iconColor: 'orange',+ },+ {+ value: 'Personal',+ icon: 'ncUser',+ iconColor: 'green',+ },+ {+ value: 'School',+ icon: 'ncGraduationCap',+ iconColor: 'purple',+ },+ {+ value: 'Non-Profit',+ icon: 'ncHeart',+ iconColor: 'pink',+ },+ ],+ rightSection: {+ themeColor: 'orange',+ moscot: 'moscotWelcomeOrange',+ imageName: 'grid',+ },+ iconSize: {+ width: 40,+ height: 40,+ },+ },+ {+ id: 2,+ question: 'What best describes your role currently?',+ inputType: 'singleSelect',+ options: (state = formState.value) => {+ const firstQuestionAns = state[1] ?? ''++ if (searchCompare('personal', firstQuestionAns as string)) {+ return [+ 'Undergraduate student',+ 'Graduate student',+ 'Consultant at Digital Agency',+ 'Individual Contributor',+ 'Team Leader',+ 'Director',+ 'C-level',+ 'VP',+ 'Business Owner',+ 'Other',+ ].map((value) => ({ value }))+ }++ if (searchCompare('school', firstQuestionAns as string)) {+ return ['Undergraduate student', 'Graduate student', 'Faculty', 'Other'].map((value) => ({ value }))+ }++ return [+ 'Consultant at Digital Agency',+ 'Individual Contributor',+ 'Team Leader',+ 'Head of Department',+ 'VP',+ 'C-level',+ 'Business Owner',+ ].map((value) => ({ value }))+ },+ rightSection: (state = formState.value) => {+ let themeColor: OnboardingRightSectionType['themeColor'] = 'orange'+ let moscot: OnboardingRightSectionType['moscot'] = 'moscotWelcomeOrange'++ const firstQuestionAns = state[1] ?? ''++ if (searchCompare('personal', firstQuestionAns as string)) {+ themeColor = 'green'+ moscot = 'moscotWelcomeGreen'+ }++ if (searchCompare('school', firstQuestionAns as string)) {+ themeColor = 'purple'+ moscot = 'moscotWelcomePurple'+ }++ return {+ themeColor,+ moscot,+ imageName: 'grid',+ }+ },+ },+ {+ id: 3,+ question: 'How many people are in your team?',+ inputType: 'singleSelect',+ options: ['Only me', '2-5', '6-10', '11-15', '16-25', '26-50', '51-100', '101+'].map((value) => ({ value })),+ rightSection: {+ themeColor: 'orange',+ moscot: 'moscotCollaboration',+ imageName: 'gallery',+ },+ },+ {+ id: 4,+ question: 'How many people work at your company?',+ inputType: 'singleSelect',+ options: ['1-19', '20-49', '50-99', '100-250', '251-500', '500-1500', '1500+'].map((value) => ({ value })),+ rightSection: {+ themeColor: 'orange',+ moscot: 'moscotCollaboration',+ imageName: 'gallery',+ },+ },+ {+ id: 5,+ question: 'How experienced are you with app building?',+ inputType: 'singleSelect',+ options: [+ {+ value: 'Beginer',+ iconType: 'indexedStepProgressBar',+ },+ {+ value: 'Intermediate',+ iconType: 'indexedStepProgressBar',+ },+ {+ value: 'Advanced',+ iconType: 'indexedStepProgressBar',+ },+ {+ value: 'Expert',+ iconType: 'indexedStepProgressBar',+ },+ ],+ rightSection: {+ themeColor: 'orange',+ moscot: 'moscotGridTableOrange',+ imageName: 'calendar',+ },+ },+ {+ id: 6,+ question: 'Which tools are you familiar with?',+ inputType: 'multiSelect',+ options: [+ {+ value: 'Airtable',+ },+ {+ value: 'Baserow',+ },+ {+ value: 'Monday',+ },+ {+ value: 'Softr',+ },+ {+ value: 'Notion',+ },+ {+ value: 'Coda',+ },+ {+ value: 'Retool',+ },+ {+ value: 'n8n',+ },+ {+ value: 'Zapier',+ },+ {+ value: 'Make',+ },+ {+ value: 'Other',+ resetOnSelect: true,+ },+ {+ value: 'None of the above',+ resetOnSelect: true,+ },+ ],+ minSelection: 3,+ rightSection: {+ themeColor: 'orange',+ moscot: 'moscotGridTableOrange',+ imageName: 'calendar',+ },+ },+ {+ id: 7,+ question: 'How do you want to build your database?',+ inputType: 'singleSelect',+ options: [+ {+ value: 'Build with AI',+ description: 'Describe what you wantβAI will generate the structure for you',+ icon: 'ncAutoAwesome',+ iconColor: 'purple',+ },+ // TODO: @rameshmane7218 Enable this when we have templates+ // {+ // value: 'Start with Template',+ // description: 'Pick from ready-made setups tailored to popular use cases.',+ // icon: 'ncLayout',+ // iconColor: 'orange',+ // },+ {+ value: 'Import Data',+ description: 'Bring your existing spreadsheets or databases into NocoDB.',+ icon: 'ncDownload',+ iconColor: 'green',+ },+ {+ value: 'Start from Scratch',+ description: 'Begin with a blank canvas and build your base your way.',+ icon: 'ncPlus',+ iconColor: 'brand',+ },+ ],+ rightSection: {+ themeColor: 'brand',+ moscot: 'moscotGridTableBrand',+ imageName: 'kanban',+ },+ iconSize: {+ width: 32,+ height: 32,+ },+ },+ ]+ })++ const questionsMap = computed(() => {+ return questions.value.reduce((acc, curr) => {+ acc[curr.id] = curr++ return acc+ }, {} as { [questionId: number]: OnboardingQuestionType })+ })++ const steps = computed(() => {+ return ncArrayFrom(Math.ceil(questions.value.length / 2)).map((_, index) => index + 1)+ })++ const stepper = useStepper(steps)++ const lastVisibleQuestionIndex = computed(() => {+ const index = (stepper.index.value + 1) * 2 - 1++ const question = questions.value[index]!++ if (!question || ncIsUndefined(formState.value[question.id])) {+ return index - 1+ }++ return index+ })++ const visibleQuestions = computed(() => {+ let currentVisibleQuestions: OnboardingQuestionType[] = []+ const index = (stepper.index.value + 1) * 2 - 1++ const question = questions.value[index]!++ if (!question || ncIsUndefined(formState.value[question.id])) {+ currentVisibleQuestions.push(questions.value[index - 1]!)++ return currentVisibleQuestions+ }++ currentVisibleQuestions.push(question)++ currentVisibleQuestions.unshift(questions.value[index - 1]!)++ return currentVisibleQuestions+ })++ const isFilledQuestionAnswer = (question: OnboardingQuestionType) => {+ return (+ !ncIsUndefined(formState.value[question.id]) &&+ (question.inputType === 'singleSelect'+ ? !!formState.value[question.id]+ : (formState.value[question.id] as string[]).length >= 1)+ )+ }++ const isFilledVisibleOptions = computed(() => {+ if (stepper.isLast.value) return true++ return visibleQuestions.value.every((question) => {+ return isFilledQuestionAnswer(question)+ })+ })++ const onInitOnboardingFlow = async () => {+ startedAt.value = Date.now()+ }++ const onSelectOption = (option: OnboardingOptionType, question: OnboardingQuestionType, currentStepQuestionIndex: number) => {+ let autoNavigateToNextQuestion = true++ if (question.inputType === 'singleSelect') {+ formState.value[question.id] = option.value+ }++ if (question.inputType === 'multiSelect') {+ const currentValue = (formState.value[question.id] || []) as string[]++ const resetOnSelectOptionValues =+ (ncIsFunction(question.options) ? question.options(formState.value) : question.options)+ ?.filter((op) => op.resetOnSelect)+ .map((op) => op.value) || []++ if (currentValue.includes(option.value)) {+ formState.value[question.id] = currentValue.filter((value) => value !== option.value)+ autoNavigateToNextQuestion = false+ } else {+ if (option.resetOnSelect) {+ autoNavigateToNextQuestion = false+ formState.value[question.id] = [option.value]+ } else {+ formState.value[question.id] = [+ ...currentValue.filter((value) => !resetOnSelectOptionValues.includes(value)),+ option.value,+ ]+ }+ }+ }++ const nextQuestionIndex = questions.value.findIndex((q) => q.id === question.id) + 1++ const nextQuestion = questions.value[nextQuestionIndex]++ if (!nextQuestion) {+ if (stepper.isLast.value) {+ onCompleteOnboardingFlow(false, () => {+ if (option.value === 'Start from Scratch') {+ showOnboardingFlowLocalState.value = false+ }+ })+ }++ return+ }++ if (currentStepQuestionIndex % 2 !== 0) {+ /**+ * Don't auto navigate to next question if:+ * 1. It is the last question+ * 2. User has not selected any option+ * 3. Next question is already filled (maybe they have click back button)+ */+ if (stepper.isLast.value || !autoNavigateToNextQuestion || !nextQuestion || isFilledQuestionAnswer(nextQuestion)) return++ if (question.inputType === 'singleSelect') {+ ncDelay(500).then(() => {+ stepper.goToNext()+ })+ } else if (question.inputType === 'multiSelect') {+ if ((formState.value[question.id]?.length ?? 0) >= (question.minSelection ?? 1)) {+ ncDelay(500).then(() => {+ stepper.goToNext()+ })+ }+ }+ } else if (ncIsUndefined(formState.value[nextQuestion.id]) || question.id === 1) {+ formState.value[nextQuestion.id] = nextQuestion.inputType === 'singleSelect' ? '' : []+ }+ }++ /**+ * Format time taken in minutes (mm:ss)+ * @param startTime - Timestamp when the onboarding flow is started+ * @param endTime - Timestamp when the onboarding flow is completed+ * @returns Time taken in minutes (mm:ss)+ */+ function formatTimeSpent(startTime: number, endTime: number): string {+ const totalSeconds = Math.floor((endTime - startTime) / 1000)+ const minutes = Math.floor(totalSeconds / 60)+ const seconds = totalSeconds % 60++ return `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`+ }++ const postCompleteOnboardingFlow = (skipped: boolean = false) => {+ const formattedQuestionAnswers = questions.value.map((q) => {+ const answer = formState.value[q.id]++ return {+ question: q.question,+ answer,+ }+ })++ const data = {+ timeTaken: formatTimeSpent(startedAt.value, Date.now()),+ skipped,+ questions: formattedQuestionAnswers,+ }++ $e('a:auth:onboarding-flow', data)+ }++ const onCompleteOnboardingFlow = async (skipped: boolean = false, callback?: () => void) => {+ postCompleteOnboardingFlow(skipped)++ if (skipped) {+ showOnboardingFlowLocalState.value = false+ }++ callback?.()+ }++ return {+ showOnboardingFlowLocalState,+ showOnboardingFlow,+ questions,+ questionsMap,+ formState,+ stepper,+ onInitOnboardingFlow,+ onCompleteOnboardingFlow,+ lastVisibleQuestionIndex,+ visibleQuestions,+ isFilledVisibleOptions,+ onSelectOption,+ isFilledQuestionAnswer,+ isEnabledOnboardingFlow,+ }+})