-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a78a34
commit d369b4d
Showing
24 changed files
with
576 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import { Button } from '@chakra-ui/react' | ||
import { useTypebot } from 'contexts/TypebotContext' | ||
|
||
export const PublishButton = () => { | ||
const { isPublishing, isPublished, publishTypebot } = useTypebot() | ||
|
||
return ( | ||
<Button ml={2} colorScheme={'blue'}> | ||
Publish | ||
<Button | ||
ml={2} | ||
colorScheme="blue" | ||
isLoading={isPublishing} | ||
isDisabled={isPublished} | ||
onClick={publishTypebot} | ||
> | ||
{isPublished ? 'Published' : 'Publish'} | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import prisma from 'libs/prisma' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getSession } from 'next-auth/react' | ||
import { methodNotAllowed } from 'services/api/utils' | ||
|
||
const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const session = await getSession({ req }) | ||
|
||
if (!session?.user) | ||
return res.status(401).json({ message: 'Not authenticated' }) | ||
|
||
try { | ||
if (req.method === 'POST') { | ||
const data = JSON.parse(req.body) | ||
const typebot = await prisma.publicTypebot.create({ | ||
data: { ...data }, | ||
}) | ||
return res.send(typebot) | ||
} | ||
return methodNotAllowed(res) | ||
} catch (err) { | ||
console.error(err) | ||
if (err instanceof Error) { | ||
return res.status(500).send({ title: err.name, message: err.message }) | ||
} | ||
return res.status(500).send({ message: 'An error occured', error: err }) | ||
} | ||
} | ||
|
||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import prisma from 'libs/prisma' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getSession } from 'next-auth/react' | ||
import { methodNotAllowed } from 'services/api/utils' | ||
|
||
const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const session = await getSession({ req }) | ||
|
||
if (!session?.user) | ||
return res.status(401).json({ message: 'Not authenticated' }) | ||
|
||
const id = req.query.id.toString() | ||
if (req.method === 'PUT') { | ||
const data = JSON.parse(req.body) | ||
const typebots = await prisma.publicTypebot.update({ | ||
where: { id }, | ||
data, | ||
}) | ||
return res.send({ typebots }) | ||
} | ||
return methodNotAllowed(res) | ||
} | ||
|
||
export default handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { PublicTypebot, Typebot } from 'bot-engine' | ||
import { sendRequest } from './utils' | ||
import shortId from 'short-uuid' | ||
|
||
export const parseTypebotToPublicTypebot = ( | ||
typebot: Typebot | ||
): PublicTypebot => ({ | ||
id: shortId.generate(), | ||
blocks: typebot.blocks, | ||
name: typebot.name, | ||
startBlock: typebot.startBlock, | ||
typebotId: typebot.id, | ||
theme: typebot.theme, | ||
settings: typebot.settings, | ||
publicId: typebot.publicId, | ||
}) | ||
|
||
export const createPublishedTypebot = async ( | ||
typebot: Omit<PublicTypebot, 'id'> | ||
) => | ||
sendRequest({ | ||
url: `/api/publicTypebots`, | ||
method: 'POST', | ||
body: typebot, | ||
}) | ||
|
||
export const updatePublishedTypebot = async ( | ||
id: string, | ||
typebot: Omit<PublicTypebot, 'id'> | ||
) => | ||
sendRequest({ | ||
url: `/api/publicTypebots/${id}`, | ||
method: 'PUT', | ||
body: typebot, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
margin: 0; | ||
} |
Oops, something went wrong.
d369b4d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
viewer-v2 – ./apps/viewer
viewer-v2-git-main-typebot-io.vercel.app
viewer-v2-typebot-io.vercel.app
typebot-io.vercel.app