-
Notifications
You must be signed in to change notification settings - Fork 21
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
8fc82a7
commit 1cce215
Showing
34 changed files
with
197 additions
and
228 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
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,38 @@ | ||
import { Form } from '@/models'; | ||
import { getFormFromSupabase } from '@/utils'; | ||
import { createClientComponentClient } from '@supabase/auth-helpers-nextjs'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Database } from '../../types/supabase'; | ||
import { ErrorBox } from './ErrorBox'; | ||
import { InnerChat } from '@/components/InnerChat'; | ||
|
||
|
||
export function CreateFormInner(props: { formId: string; }) { | ||
const { formId } = props; | ||
const supabase = createClientComponentClient<Database>(); | ||
const [form, setForm] = useState<Form | null>(null); | ||
const [error, setError] = useState<Error | null>(null); | ||
useEffect(() => { | ||
if (!form) { | ||
getFormFromSupabase(formId, supabase).then((maybeForm) => { | ||
if (maybeForm instanceof Error) { | ||
console.error(maybeForm.message); | ||
setError(maybeForm); | ||
} else { | ||
setForm(maybeForm); | ||
} | ||
}); | ||
} | ||
}, []); // The empty array ensures this effect runs only once on mount | ||
return form ? ( | ||
<InnerChat form={form} supabase={supabase} /> | ||
) : ( | ||
<> | ||
{error ? ( | ||
ErrorBox(error) | ||
) : ( | ||
<h1 className="text-3xl font-extrabold mb-6">Loading...</h1> | ||
)} | ||
</> | ||
); | ||
} |
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,12 @@ | ||
import React from 'react'; | ||
|
||
export function ErrorBox( | ||
error: Error | ||
): React.ReactNode { | ||
return ( | ||
<div className="w-4/5 md:w-1/2 lg:w-1/3 bg-red-300 shadow-md p-6 rounded-lg mt-4"> | ||
<h1 className="text-xl font-extrabold mb-6">Error</h1> | ||
<p className="font-mono text-sm whitespace-pre-wrap">{error.message}</p> | ||
</div> | ||
); | ||
} |
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,10 @@ | ||
import React from 'react'; | ||
|
||
export function MiniSpinner() { | ||
return ( | ||
<div | ||
className="inline-block h-5 w-5 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]" | ||
role="status" | ||
><span className="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]">Loading...</span></div> | ||
); | ||
} |
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,15 @@ | ||
import React from 'react'; | ||
|
||
export function SubmissionBox(submission: object): React.ReactNode { | ||
return ( | ||
<div | ||
id="submissionBox" | ||
className="w-4/5 md:w-1/2 lg:w-1/3 bg-white shadow-md p-6 rounded-lg mt-4" | ||
> | ||
<h1 className="text-xl font-extrabold mb-6">Submission</h1> | ||
<p className="font-mono text-sm whitespace-pre-wrap"> | ||
{JSON.stringify(submission, null, 2)} | ||
</p> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.