diff --git a/src/features/surveys/managers/createSurveyManager.ts b/src/features/surveys/managers/createSurveyManager.ts index 8e4716c0..59699b4c 100644 --- a/src/features/surveys/managers/createSurveyManager.ts +++ b/src/features/surveys/managers/createSurveyManager.ts @@ -9,9 +9,9 @@ import useCopyToClipboard from 'shared/hooks/useCopyToClipboard'; export const useCreateSurveyManager = () => { const [title, setTitle] = useState(''); const [pack, setPack] = useState([]); + const [error, setError] = useState(''); const { user } = useApplicationContext(); - const [buttonDisable, setButtonDisable] = useState(false); const [isCreating, setIsCreating] = useState(false); const router = useRouter(); @@ -47,7 +47,8 @@ export const useCreateSurveyManager = () => { }, [startDate, endDate]); const createSurvey = async () => { - setButtonDisable(true); + if (!title) return setError('Required field'); + setIsCreating(true); try { @@ -72,7 +73,6 @@ export const useCreateSurveyManager = () => { toast.error('Survey creation failed'); } setIsCreating(false); - setButtonDisable(false); }; const filterPassedTime = (time: string | number | Date) => { @@ -90,6 +90,7 @@ export const useCreateSurveyManager = () => { }; return { title, + error, pack, handleChangeTitle, startDate, @@ -100,7 +101,6 @@ export const useCreateSurveyManager = () => { filterPassedSelectedTime, handleEmotePick, createSurvey, - buttonDisable, isCreating, }; }; diff --git a/src/pages/survey/create/index.tsx b/src/pages/survey/create/index.tsx index 369bf495..cc90af77 100644 --- a/src/pages/survey/create/index.tsx +++ b/src/pages/survey/create/index.tsx @@ -12,6 +12,7 @@ function SurveyCreatePage() { const { title, pack, + error, handleChangeTitle, startDate, setStartDate, @@ -21,7 +22,6 @@ function SurveyCreatePage() { filterPassedSelectedTime, handleEmotePick, createSurvey, - buttonDisable, isCreating, } = useCreateSurveyManager(); @@ -39,6 +39,7 @@ function SurveyCreatePage() { label="Survey title" placeholder="Title..." value={title} + error={!title ? error : undefined} onChange={handleChangeTitle} />
@@ -106,7 +107,6 @@ function SurveyCreatePage() {