Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BitBuilder] Add "Close form" button #62

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/pages/forms/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import { Database } from '../../../types/supabase';
import ResponsesTable from '../../components/home/modes/ResponsesTable';

export default function FormDetailPage() {
const closeForm = async () => {
const { data, error } = await supabase
.from('forms')
.update({ is_open: false })
.eq('id', form.id);
if (error) {
console.error('Error closing form:', error);
} else {
setForm(data[0]);
}
};
const { isLoading: isSessionLoading, session, error } = useSessionContext();
const supabase = createClientComponentClient<Database>();
const [user, setUser] = useState<null | User>(null);
Expand Down Expand Up @@ -83,6 +94,9 @@ export default function FormDetailPage() {
View live form
</button>
</Link>
<button onClick={closeForm} className={`rounded-md px-3 py-2 text-sm font-semibold shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 ${form.is_open ? 'bg-indigo-600 text-white hover:bg-indigo-500' : 'bg-gray-300 text-gray-500 cursor-not-allowed'}`} disabled={!form.is_open}>
Close form
</button>
</div>
{form.created_at && (
<p className="text-xs text-gray-600">
Expand Down Expand Up @@ -151,4 +165,4 @@ function respectNewLines(text: string | null | undefined) {
<br />
</span>
));
}
}
Loading