diff --git a/src/components/app/ProjectSettings/ProjectSettings.tsx b/src/components/app/ProjectSettings/ProjectSettings.tsx
index 13abbee..34343cd 100644
--- a/src/components/app/ProjectSettings/ProjectSettings.tsx
+++ b/src/components/app/ProjectSettings/ProjectSettings.tsx
@@ -23,12 +23,14 @@ import {
import GithubRepoChooser from '../GithubRepoChooser/GithubRepoChooser';
import React from 'react';
import Link from 'next/link';
-import { useRouter } from 'next/navigation';
export default function ProjectSettings(project: Project) {
- const router = useRouter();
const [ghRepo, setGhRepo] = React.useState('');
+ const [hasSubmitted, setHasSubmitted] = React.useState(false);
const apiUrl = `https://${window.location.hostname}/api/feedback/${project.id}`;
+ React.useEffect(() => {
+ setHasSubmitted(project.github !== '');
+ }, [project.github]);
return (
@@ -133,7 +135,7 @@ export default function ProjectSettings(project: Project) {
onSelect={(repo) => {
setGhRepo(`https://github.com/${repo}`);
}}
- selected={project.github!.replace('https://github.com/', '')}
+ selected={project.github ? project.github.replace('https://github.com/', '') : ''}
/>
Not the results you were expecting? You may have not allowed your user in the{' '}
@@ -164,7 +166,7 @@ export default function ProjectSettings(project: Project) {
key={ghRepo}
schemaName={'githubSettings'}
action={githubSettings}
- onActionComplete={() => router.refresh()}
+ onActionComplete={() => setHasSubmitted(true)}
/>
@@ -174,7 +176,7 @@ export default function ProjectSettings(project: Project) {
Make sure your setup works!
- {project.github ? (
+ {hasSubmitted ? (
({
submitText = 'Submit',
submitClassname,
}: UniversalFormProps) {
- const [state, formAction] = useActionState(action, null);
+ // @ts-ignore idk why this error is happening, first apprearing on the react 19 update.
+ const [state, formAction] = useActionState<{ success: boolean; error?: string }>(action, null);
const schema = schemaDb.find((s) => s.name === schemaName)?.zod;
if (!schema) {
throw new Error(`Schema "${schemaName}" not found`);
}
+ // Initialize default values for all fields
+ const initialValues = React.useMemo(() => {
+ const values: Record = {};
+ fields.forEach((field) => {
+ values[field.name] = field.value ?? ''; // Use empty string as fallback
+ });
+ return { ...values, ...defaultValues };
+ }, [fields, defaultValues]);
+
const form = useForm>({
resolver: zodResolver(schema),
- defaultValues: (defaultValues || {}) as z.infer,
+ defaultValues: initialValues as z.infer,
});
- // pretend nothing is happening on here
React.useEffect(() => {
- // @ts-ignore
if (state && !state.success) {
- // @ts-ignore
toast.error(state.error);
}
if (state) {
onActionComplete?.(state);
}
- }, [state]);
+ }, [state, onActionComplete]);
return (
);
-}
+}
\ No newline at end of file