2
0

feat: Add custom domains

This commit is contained in:
Baptiste Arnaud
2022-02-18 14:57:10 +01:00
parent 1c178e01a6
commit f3ecb948a1
18 changed files with 694 additions and 66 deletions

View File

@ -0,0 +1,47 @@
import { CustomDomain } from 'db'
import { Credentials } from 'models'
import useSWR from 'swr'
import { sendRequest } from 'utils'
import { fetcher } from './utils'
export const useCustomDomains = ({
userId,
onError,
}: {
userId?: string
onError: (error: Error) => void
}) => {
const { data, error, mutate } = useSWR<
{ customDomains: CustomDomain[] },
Error
>(userId ? `/api/users/${userId}/customDomains` : null, fetcher)
if (error) onError(error)
return {
customDomains: data?.customDomains,
isLoading: !error && !data,
mutate,
}
}
export const createCustomDomain = async (
userId: string,
customDomain: Omit<CustomDomain, 'ownerId'>
) =>
sendRequest<{
credentials: Credentials
}>({
url: `/api/users/${userId}/customDomains`,
method: 'POST',
body: customDomain,
})
export const deleteCustomDomain = async (
userId: string,
customDomain: string
) =>
sendRequest<{
credentials: Credentials
}>({
url: `/api/users/${userId}/customDomains/${customDomain}`,
method: 'DELETE',
})

View File

@ -18,6 +18,7 @@ export const parseTypebotToPublicTypebot = (
settings: typebot.settings,
theme: typebot.theme,
variables: typebot.variables,
customDomain: typebot.customDomain,
})
export const parseBlocksToPublicBlocks = (blocks: Block[]): PublicBlock[] =>

View File

@ -241,7 +241,12 @@ export const parseNewTypebot = ({
name: string
}): Omit<
Typebot,
'createdAt' | 'updatedAt' | 'id' | 'publishedTypebotId' | 'publicId'
| 'createdAt'
| 'updatedAt'
| 'id'
| 'publishedTypebotId'
| 'publicId'
| 'customDomain'
> => {
const startBlockId = shortId.generate()
const startStepId = shortId.generate()