Skip to content

Commit

Permalink
feat: onboarding (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
ephraimduncan authored Jun 8, 2024
1 parent ce97254 commit 80091ea
Show file tree
Hide file tree
Showing 32 changed files with 1,870 additions and 426 deletions.
2 changes: 2 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@trpc/react-query": "next",
"@trpc/server": "next",
"date-fns": "^3.6.0",
"framer-motion": "^11.2.10",
"lucide-react": "^0.379.0",
"minio": "^8.0.0",
"next": "14.2.3",
Expand All @@ -39,6 +40,7 @@
"react-dom": "^18.3.1",
"react-hook-form": "^7.51.5",
"server-only": "^0.0.1",
"shiki": "^1.6.3",
"sonner": "^1.4.41",
"superjson": "^2.2.1",
"ts-pattern": "^5.1.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/(landing)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ const HomePage = () => {
<div className="bg-[#d4d4d4] dark:bg-[#404040]"></div>
</div>
<div>
<div className="overflow-scroll py-4">
<div className="py-4">
<pre className="px-[--card-padding]">
<code className="font-mono text-sm">
{`<form
Expand Down
13 changes: 13 additions & 0 deletions apps/web/src/app/(main)/_actions/revalidateDashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use server';

import { revalidatePath } from 'next/cache';

// eslint-disable-next-line @typescript-eslint/require-await
export const revalidateDashboard = async () => {
revalidatePath('/dashboard');
};

// eslint-disable-next-line @typescript-eslint/require-await
export const revalidateFromClient = async (route: string) => {
revalidatePath(route);
};
6 changes: 6 additions & 0 deletions apps/web/src/app/(main)/_components/user-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export const UserDropdown = ({
>
<Link href="/dashboard/settings">Settings</Link>
</DropdownMenuItem>
<DropdownMenuItem
className="cursor-pointer text-muted-foreground"
asChild
>
<Link href="/onboarding">Onboarding</Link>
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuSub>
Expand Down
40 changes: 0 additions & 40 deletions apps/web/src/app/(main)/account/page.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,13 @@ export function CreateFormDialog() {
const router = useRouter();
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
defaultValues: {
name: '',
description: '',
returnUrl: '',
keys: [''],
},
});
const [showDialog, setShowDialog] = useState<boolean>(false);
const [_isCreatePending, startCreateTransaction] = useTransition();
const [isCreatePending, startCreateTransaction] = useTransition();

const { mutateAsync: createNewForm } = api.form.create.useMutation();

const createPost = (data: z.infer<typeof FormSchema>) => {
const createForm = (data: z.infer<typeof FormSchema>) => {
startCreateTransaction(async () => {
await createNewForm(
{
Expand All @@ -86,7 +80,7 @@ export function CreateFormDialog() {
};

function onSubmit(data: z.infer<typeof FormSchema>) {
createPost(data);
createForm(data);

setShowDialog(false);
}
Expand Down Expand Up @@ -159,6 +153,7 @@ export function CreateFormDialog() {
<Button
onClick={form.handleSubmit(onSubmit)}
className="mt-2 w-full"
loading={isCreatePending}
>
Create Form
</Button>
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/app/(main)/form/[id]/copy-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { Copy } from 'lucide-react';
import { ClipboardIcon } from 'lucide-react';
import { toast } from 'sonner';

import { useCopyToClipboard } from '~/lib/hooks/use-copy-to-clipboard';
Expand All @@ -17,11 +17,11 @@ export default function CopyFormId({ formId }: CopyFormIdProps) {
<span className="inline-flex items-center rounded-lg bg-muted px-2 py-0.5 text-sm font-medium">
{formId}
</span>
<Copy
<ClipboardIcon
onClick={() =>
copy(formId).then(() => {
toast('Copied to Clipboard', {
icon: <Copy className="h-4 w-4" />,
icon: <ClipboardIcon className="h-4 w-4" />,
});
})
}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/app/(main)/form/[id]/form-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Switch } from '@formbase/ui/primitives/switch';

import { api } from '~/lib/trpc/react';

import { refreshDashboardAfterDeletion } from '../_actions/refresh-dashboard-after-deletion';
import { revalidateDashboard } from '../../_actions/revalidateDashboard';
import { DeleteFormDialog } from './delete-form-dialog';

const formNameSchema = z.object({
Expand Down Expand Up @@ -65,7 +65,7 @@ export function FormSettings({ form }: FormSettingsProps) {
}

const redirectToDashboard = () => {
void refreshDashboardAfterDeletion();
void revalidateDashboard();
router.push('/dashboard');
};

Expand Down

This file was deleted.

94 changes: 94 additions & 0 deletions apps/web/src/app/(main)/onboarding/form/code-example-step.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
Tabs,
TabsContent,
TabsList,
TabsTrigger,
} from '@formbase/ui/primitives/tabs';
import { cn } from '@formbase/ui/utils/cn';

import { CopyButton } from '~/components/copy-button';
import { highlightCode } from '~/lib/highlight-code';

import SendFormSubmissionButton from './send-submission-button';

type CodeExampleStepProps = {
formId: string | null;
};

export const CodeExampleStep = async ({ formId }: CodeExampleStepProps) => {
const htmlCode = await highlightCode(`<form
action="https://formbase.dev/s/${formId ?? 'abcdefghijkl'}" method="POST"
enctype="multipart/form-data"
>
<input type="text" name="name" />
<input type="email" name="email" />
<textarea name="message"></textarea>
<button type="submit">Submit</button>
</form>`);

const reactCode =
await highlightCode(`export default function FormbaseForm() {
return (
<form
action="https://formbase.dev/s/${formId ?? 'abcdefghijkl'}"
method="POST"
encType="multipart/form-data"
>
<input type="text" name="name" />
<input type="email" name="email" />
<textarea name="message"></textarea>
<button type="submit">Submit</button>
</form>
);
}`);

return (
<div
className={cn('-mt-0.5', {
'pointer-events-none opacity-50 select-none': formId === null,
})}
>
<h2 className="text-xl font-semibold">Send a submission</h2>
<div className="text-gray-600 dark:text-muted-foreground mt-2">
<div className="space-y-4">
<p>Use the code below to recieve your first submission</p>

<Tabs defaultValue="html">
<TabsList>
<TabsTrigger value="html">HTML</TabsTrigger>
<TabsTrigger value="react">React</TabsTrigger>
</TabsList>
<TabsContent value="html" className="relative">
<div
className="mt-4 rounded-md"
dangerouslySetInnerHTML={{
__html: htmlCode,
}}
/>
<CopyButton
text={htmlCode}
className="absolute top-4 text-white right-4"
/>
</TabsContent>
<TabsContent value="react" className="relative">
<div
className="mt-4 rounded-md"
dangerouslySetInnerHTML={{
__html: reactCode,
}}
/>
<CopyButton
text={reactCode}
className="absolute top-4 text-white right-4"
/>
</TabsContent>
</Tabs>

<SendFormSubmissionButton formId={formId} />
</div>
</div>
</div>
);
};
Loading

0 comments on commit 80091ea

Please sign in to comment.