feat: ✨ Add custom domains
This commit is contained in:
47
apps/builder/services/customDomains.ts
Normal file
47
apps/builder/services/customDomains.ts
Normal 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',
|
||||
})
|
@ -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[] =>
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user