Skip to content

Commit

Permalink
implement #68;
Browse files Browse the repository at this point in the history
  • Loading branch information
ellipsis-dev-beta[bot] authored Jan 21, 2024
1 parent 3141221 commit e5eea77
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
10 changes: 10 additions & 0 deletions src/components/ClosedForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';

export default function ClosedForm() {
return (
<div>
<p>This form is no longer accepting responses. If you believe this is an error, contact the form author.</p>
<button onClick={() => window.location.href='https://talkform.ai/'}>Go to TalkForm.ai</button>
</div>
);
}
45 changes: 21 additions & 24 deletions src/pages/forms/fill/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,32 +46,29 @@ export default function CreateForm() {
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 ? (
const supabase = createClientComponentClient<Database>();
const [form, setForm] = useState<Form | null>(null);
const [isFormOpen, setIsFormOpen] = useState<boolean>(true);
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);
setIsFormOpen(maybeForm.is_open);
}
});
}
}, []); // The empty array ensures this effect runs only once on mount
import ClosedForm from '@/components/ClosedForm';
return isFormOpen ? (
<InnerChat form={form} supabase={supabase} />
) : (
<>
{error ? (
ErrorBox(error)
) : (
<h1 className="text-3xl font-extrabold mb-6">Loading...</h1>
)}
</>
<ClosedForm />
);
}
export function InnerChat(props: {
form: Form;
supabase: SupabaseClient<Database>;
Expand Down Expand Up @@ -239,4 +236,4 @@ function SubmissionBox(submission: object): React.ReactNode {
</p>
</div>
);
}
}

0 comments on commit e5eea77

Please sign in to comment.