fix(challenge modal): user could submit empty answer

This commit is contained in:
Tom (plebeius.eth)
2025-01-24 15:49:54 +01:00
parent 515007cbf6
commit a7beb3aebb
@@ -45,6 +45,7 @@ const Challenge = ({ challenge, closeModal }: ChallengeProps) => {
const onEnterKey = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key !== 'Enter') return;
if (!answers[currentChallengeIndex]) return;
if (challenges[currentChallengeIndex + 1]) {
setCurrentChallengeIndex((prev) => prev + 1);
} else {
@@ -112,7 +113,11 @@ const Challenge = ({ challenge, closeModal }: ChallengeProps) => {
<div className={styles.challengeFooter}>
<div className={styles.counter}>{t('challenge_counter', { index: currentChallengeIndex + 1, total: challenges?.length })}</div>
<span className={styles.buttons}>
{!challenges[currentChallengeIndex + 1] && <button onClick={onSubmit}>{t('submit')}</button>}
{!challenges[currentChallengeIndex + 1] && (
<button onClick={onSubmit} disabled={!answers[currentChallengeIndex]}>
{t('submit')}
</button>
)}
{challenges.length > 1 && (
<button disabled={!challenges[currentChallengeIndex - 1]} onClick={() => setCurrentChallengeIndex((prev) => prev - 1)}>
{t('previous')}