Skip to content

Commit d0ec112

Browse files
authored
Disable create Project Button after first click (#107)
* Disable create Project Button after first click * removed unnecessary line of code * updated the text message - No bibles for this language
1 parent 73e0aae commit d0ec112

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

src/layouts/projects/CreateProjectModal.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({
5151
error = null,
5252
}) => {
5353
const { t } = useTranslation();
54+
const [isSubmitting, setIsSubmitting] = useState(false);
5455

5556
const [formData, setFormData] = useState<FormData>({
5657
title: '',
@@ -76,6 +77,7 @@ export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({
7677
books: [],
7778
});
7879
}
80+
setIsSubmitting(false);
7981
}, [isOpen]);
8082

8183
useEffect(() => {
@@ -109,11 +111,14 @@ export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({
109111
};
110112

111113
const handleSubmit = async (): Promise<void> => {
114+
if (isSubmitting) {
115+
return;
116+
}
112117
try {
113118
if (!formData.targetLanguage || !formData.sourceLanguage || !formData.sourceBible) {
114119
return;
115120
}
116-
121+
setIsSubmitting(true);
117122
const projectData: CreateProjectData = {
118123
title: formData.title,
119124
targetLanguage: formData.targetLanguage,
@@ -127,6 +132,7 @@ export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({
127132
Logger.logException(error instanceof Error ? error : new Error(String(error)), {
128133
source: 'create project submit',
129134
});
135+
setIsSubmitting(false);
130136
}
131137
};
132138

@@ -144,7 +150,7 @@ export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({
144150
}
145151
};
146152

147-
const isButtonDisabled = isLoading || !isFormValid();
153+
const isButtonDisabled = isLoading || isSubmitting || !isFormValid();
148154

149155
if (languagesError) {
150156
return (
@@ -172,7 +178,6 @@ export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({
172178
<DialogTitle>{t('createProject')}</DialogTitle>
173179
</DialogHeader>
174180
<div className='space-y-6 py-6'>
175-
{/* Project Title */}
176181
<div className='space-y-2'>
177182
<Label className='gap-1' htmlFor='title'>
178183
<span style={{ color: 'red' }}>*</span>
@@ -235,11 +240,17 @@ export const CreateProjectModal: React.FC<CreateProjectModalProps> = ({
235240
/>
236241
</SelectTrigger>
237242
<SelectContent>
238-
{sourceBibles?.map(bible => (
239-
<SelectItem key={bible.id} value={bible.id.toString()}>
240-
{bible.name} ({bible.abbreviation})
241-
</SelectItem>
242-
))}
243+
{!sourceBibles || sourceBibles.length === 0 ? (
244+
<div className='p-1 text-center text-sm text-gray-500'>
245+
No bibles for this language
246+
</div>
247+
) : (
248+
sourceBibles.map(bible => (
249+
<SelectItem key={bible.id} value={bible.id.toString()}>
250+
{bible.name} ({bible.abbreviation})
251+
</SelectItem>
252+
))
253+
)}
243254
</SelectContent>
244255
</Select>
245256
</div>

0 commit comments

Comments
 (0)