2
0

feat(editor): Team workspaces

This commit is contained in:
Baptiste Arnaud
2022-05-13 15:22:44 -07:00
parent 6c2986590b
commit f0fdf08b00
132 changed files with 3354 additions and 1228 deletions

View File

@ -15,6 +15,7 @@ import {
import { GoogleLogo } from 'assets/logos'
import { NextChakraLink } from 'components/nextChakra/NextChakraLink'
import { Info } from 'components/shared/Info'
import { useWorkspace } from 'contexts/WorkspaceContext'
import React from 'react'
import { getGoogleSheetsConsentScreenUrl } from 'services/integrations'
@ -25,6 +26,7 @@ type Props = {
}
export const GoogleSheetConnectModal = ({ stepId, isOpen, onClose }: Props) => {
const { workspace } = useWorkspace()
return (
<Modal isOpen={isOpen} onClose={onClose} size="lg">
<ModalOverlay />
@ -54,7 +56,8 @@ export const GoogleSheetConnectModal = ({ stepId, isOpen, onClose }: Props) => {
variant="outline"
href={getGoogleSheetsConsentScreenUrl(
window.location.href,
stepId
stepId,
workspace?.id
)}
mx="auto"
>

View File

@ -1,10 +1,8 @@
import { Stack, useDisclosure, Text } from '@chakra-ui/react'
import { CredentialsDropdown } from 'components/shared/CredentialsDropdown'
import { Input, Textarea } from 'components/shared/Textbox'
import { useTypebot } from 'contexts/TypebotContext'
import { CredentialsType, SendEmailOptions } from 'models'
import React, { useEffect, useState } from 'react'
import { isDefined } from 'utils'
import React, { useState } from 'react'
import { SmtpConfigModal } from './SmtpConfigModal'
type Props = {
@ -13,16 +11,9 @@ type Props = {
}
export const SendEmailSettings = ({ options, onOptionsChange }: Props) => {
const { owner } = useTypebot()
const { isOpen, onOpen, onClose } = useDisclosure()
const [refreshCredentialsKey, setRefreshCredentialsKey] = useState(0)
useEffect(() => {
if (isDefined(options.replyTo) || !owner?.email) return
handleReplyToChange(owner.email)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const handleCredentialsSelect = (credentialsId?: string) => {
setRefreshCredentialsKey(refreshCredentialsKey + 1)
onOptionsChange({
@ -95,7 +86,7 @@ export const SendEmailSettings = ({ options, onOptionsChange }: Props) => {
<Input
onChange={handleReplyToChange}
defaultValue={options.replyTo}
placeholder={owner?.email ?? 'email@gmail.com'}
placeholder={'email@gmail.com'}
/>
</Stack>
<Stack>

View File

@ -16,6 +16,7 @@ import { createCredentials } from 'services/user'
import { testSmtpConfig } from 'services/integrations'
import { isNotDefined } from 'utils'
import { SmtpConfigForm } from './SmtpConfigForm'
import { useWorkspace } from 'contexts/WorkspaceContext'
type Props = {
isOpen: boolean
@ -29,6 +30,7 @@ export const SmtpConfigModal = ({
onClose,
}: Props) => {
const { user } = useUser()
const { workspace } = useWorkspace()
const [isCreating, setIsCreating] = useState(false)
const toast = useToast({
position: 'top-right',
@ -40,7 +42,7 @@ export const SmtpConfigModal = ({
})
const handleCreateClick = async () => {
if (!user?.email) return
if (!user?.email || !workspace?.id) return
setIsCreating(true)
const { error: testSmtpError } = await testSmtpConfig(
smtpConfig,
@ -53,10 +55,11 @@ export const SmtpConfigModal = ({
description: "We couldn't send the test email with your configuration",
})
}
const { data, error } = await createCredentials(user.id, {
const { data, error } = await createCredentials({
data: smtpConfig,
name: smtpConfig.from.email as string,
type: CredentialsType.SMTP,
workspaceId: workspace.id,
})
setIsCreating(false)
if (error) return toast({ title: error.name, description: error.message })

View File

@ -23,10 +23,13 @@ export const TypebotLinkSettingsForm = ({
return (
<Stack>
<TypebotsDropdown
typebotId={options.typebotId}
onSelectTypebotId={handleTypebotIdChange}
/>
{typebot && (
<TypebotsDropdown
typebotId={options.typebotId}
onSelectTypebotId={handleTypebotIdChange}
currentWorkspaceId={typebot.workspaceId as string}
/>
)}
<BlocksDropdown
blocks={
typebot &&

View File

@ -9,16 +9,22 @@ import { byId } from 'utils'
type Props = {
typebotId?: string
currentWorkspaceId: string
onSelectTypebotId: (typebotId: string | 'current') => void
}
export const TypebotsDropdown = ({ typebotId, onSelectTypebotId }: Props) => {
export const TypebotsDropdown = ({
typebotId,
onSelectTypebotId,
currentWorkspaceId,
}: Props) => {
const { query } = useRouter()
const toast = useToast({
position: 'top-right',
status: 'error',
})
const { typebots, isLoading } = useTypebots({
workspaceId: currentWorkspaceId,
allFolders: true,
onError: (e) => toast({ title: e.name, description: e.message }),
})