NewMemoryPopup error control

This commit is contained in:
Chaebean Yang 2025-06-07 12:08:15 +09:00
parent c7c4153220
commit b73519c5db

View File

@ -26,9 +26,17 @@
let customLocation = ''; let customLocation = '';
let customLocationInput: HTMLInputElement; let customLocationInput: HTMLInputElement;
let images: File[] = []; let images: File[] = [];
let showLocationError = false; let showLocationError = false;
let showImageError = false; let showImageError = false;
let hasAttemptedSubmit = false;
let isFormValid = true;
$: if (hasAttemptedSubmit) {
isFormValid = (
(selectedLocation !== '' && (!isCustomLocation() || customLocation.trim() !== '')) &&
images.length > 0
);
}
const GOOGLE_PLACES_API_KEY = import.meta.env.VITE_GOOGLE_PLACES_API_KEY; const GOOGLE_PLACES_API_KEY = import.meta.env.VITE_GOOGLE_PLACES_API_KEY;
@ -105,6 +113,8 @@
} }
async function handleAddMemory() { async function handleAddMemory() {
hasAttemptedSubmit = true;
showLocationError = selectedLocation === '' || (isCustomLocation() && customLocation.trim() === ''); showLocationError = selectedLocation === '' || (isCustomLocation() && customLocation.trim() === '');
showImageError = images.length === 0; showImageError = images.length === 0;
@ -243,7 +253,7 @@
<Button text="Cancel" type="gray" onClick={handleCancelClick} /> <Button text="Cancel" type="gray" onClick={handleCancelClick} />
<Button text="Add a new memory" type="orange" <Button text="Add a new memory" type="orange"
onClick={handleAddMemory} onClick={handleAddMemory}
disabled={showLocationError || showImageError}/> disabled={hasAttemptedSubmit && !isFormValid}/>
</div> </div>
</div> </div>
</div> </div>