2
0

feat(integration): Add Google Sheets integration

This commit is contained in:
Baptiste Arnaud
2022-01-18 18:25:18 +01:00
parent 2814a352b2
commit f49b5143cf
67 changed files with 2560 additions and 391 deletions

View File

@ -1,12 +1,4 @@
import {
BubbleStep,
BubbleStepType,
ChoiceItem,
InputStep,
InputStepType,
LogicStepType,
LogicStep,
} from 'models'
import { ChoiceItem, DraggableStep, DraggableStepType } from 'models'
import {
createContext,
Dispatch,
@ -16,9 +8,6 @@ import {
useState,
} from 'react'
export type DraggableStep = BubbleStep | InputStep | LogicStep
export type DraggableStepType = BubbleStepType | InputStepType | LogicStepType
const dndContext = createContext<{
draggedStepType?: DraggableStepType
setDraggedStepType: Dispatch<SetStateAction<DraggableStepType | undefined>>

View File

@ -1,4 +1,4 @@
import { useToast } from '@chakra-ui/react'
import { ToastId, useToast } from '@chakra-ui/react'
import { PublicTypebot, Settings, Theme, Typebot } from 'models'
import { useRouter } from 'next/router'
import {
@ -43,7 +43,7 @@ const typebotContext = createContext<
isPublishing: boolean
hasUnsavedChanges: boolean
isSavingLoading: boolean
save: () => void
save: () => Promise<ToastId | undefined>
undo: () => void
updateTypebot: (updates: UpdateTypebotPayload) => void
publishTypebot: () => void

View File

@ -1,13 +1,6 @@
import { Coordinates } from 'contexts/GraphContext'
import { WritableDraft } from 'immer/dist/internal'
import {
Block,
BubbleStepType,
InputStepType,
LogicStepType,
Step,
Typebot,
} from 'models'
import { Block, DraggableStep, DraggableStepType, Typebot } from 'models'
import { parseNewBlock } from 'services/typebots'
import { Updater } from 'use-immer'
import { createStepDraft, deleteStepDraft } from './steps'
@ -15,7 +8,7 @@ import { createStepDraft, deleteStepDraft } from './steps'
export type BlocksActions = {
createBlock: (
props: Coordinates & {
step: BubbleStepType | InputStepType | LogicStepType | Step
step: DraggableStep | DraggableStepType
}
) => void
updateBlock: (blockId: string, updates: Partial<Omit<Block, 'id'>>) => void
@ -28,7 +21,7 @@ export const blocksActions = (setTypebot: Updater<Typebot>): BlocksActions => ({
y,
step,
}: Coordinates & {
step: BubbleStepType | InputStepType | LogicStepType | Step
step: DraggableStep | DraggableStepType
}) => {
setTypebot((typebot) => {
const newBlock = parseNewBlock({

View File

@ -1,10 +1,9 @@
import {
BubbleStepType,
ChoiceInputStep,
InputStepType,
Step,
Typebot,
LogicStepType,
DraggableStep,
DraggableStepType,
} from 'models'
import { parseNewStep } from 'services/typebots'
import { Updater } from 'use-immer'
@ -16,7 +15,7 @@ import { isChoiceInput } from 'utils'
export type StepsActions = {
createStep: (
blockId: string,
step: BubbleStepType | InputStepType | LogicStepType | Step,
step: DraggableStep | DraggableStepType,
index?: number
) => void
updateStep: (
@ -30,7 +29,7 @@ export type StepsActions = {
export const stepsAction = (setTypebot: Updater<Typebot>): StepsActions => ({
createStep: (
blockId: string,
step: BubbleStepType | InputStepType | LogicStepType | Step,
step: DraggableStep | DraggableStepType,
index?: number
) => {
setTypebot((typebot) => {
@ -76,7 +75,7 @@ export const deleteStepDraft = (
export const createStepDraft = (
typebot: WritableDraft<Typebot>,
step: BubbleStepType | InputStepType | LogicStepType | Step,
step: DraggableStep | DraggableStepType,
blockId: string,
index?: number
) => {

View File

@ -1,4 +1,3 @@
import { User } from 'db'
import { useSession } from 'next-auth/react'
import { useRouter } from 'next/router'
import {
@ -13,6 +12,8 @@ import { isDefined } from 'utils'
import { updateUser as updateUserInDb } from 'services/user'
import { useToast } from '@chakra-ui/react'
import { deepEqual } from 'fast-equals'
import { useCredentials } from 'services/credentials'
import { Credentials, User } from 'db'
const userContext = createContext<{
user?: User
@ -20,6 +21,7 @@ const userContext = createContext<{
isSaving: boolean
hasUnsavedChanges: boolean
isOAuthProvider: boolean
credentials: Credentials[]
updateUser: (newUser: Partial<User>) => void
saveUser: () => void
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@ -29,8 +31,12 @@ const userContext = createContext<{
export const UserContext = ({ children }: { children: ReactNode }) => {
const router = useRouter()
const { data: session, status } = useSession()
const [user, setUser] = useState<User>()
const [user, setUser] = useState<User | undefined>()
const { credentials } = useCredentials({
userId: user?.id,
onError: (error) =>
toast({ title: error.name, description: error.message }),
})
const [isSaving, setIsSaving] = useState(false)
const isOAuthProvider = useMemo(
() => (session?.providerType as boolean | undefined) ?? false,
@ -69,9 +75,13 @@ export const UserContext = ({ children }: { children: ReactNode }) => {
setIsSaving(true)
const { error } = await updateUserInDb(user.id, user)
if (error) toast({ title: error.name, description: error.message })
await refreshUser()
setIsSaving(false)
}
const refreshUser = async () => {
await fetch('/api/auth/session?update')
reloadSession()
setIsSaving(false)
}
return (
@ -84,6 +94,7 @@ export const UserContext = ({ children }: { children: ReactNode }) => {
isLoading: status === 'loading',
hasUnsavedChanges,
isOAuthProvider,
credentials: credentials ?? [],
}}
>
{children}