Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions frontend/src/app/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ export const addStore = async (
}
}

if (uploadedPhotoUrls.length === 0) {
return {
inputs: rawData,
message: 'At least one photo is required',
timestamp: new Date().toISOString(),
error: 'At least one photo is required',
};
}

rawData.photos = uploadedPhotoUrls;
const finalValidation = addStoreFormSchema.safeParse(rawData);

Expand Down Expand Up @@ -327,6 +336,15 @@ export const editStore = async (
}
}

if (existingPhotoUrls.length === 0 && uploadedPhotoUrls.length === 0) {
return {
inputs: rawData,
message: 'At least one photo is required',
timestamp: new Date().toISOString(),
error: 'At least one photo is required',
};
}

rawData.photos = [...existingPhotoUrls, ...uploadedPhotoUrls];
const finalValidation = editStoreFormSchema.safeParse(rawData);

Expand Down
8 changes: 7 additions & 1 deletion frontend/src/app/user/locations/add/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ export function AddStoreForm({
const handleSubmit = useCallback(
(event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

if (selectedImages.length === 0) {
toast.error('Please add at least one photo');
return;
}

const formData = new FormData(event.currentTarget);
const latInput = latitudeRef.current?.value ?? '';
const lngInput = longitudeRef.current?.value ?? '';
Expand Down Expand Up @@ -678,7 +684,7 @@ export function AddStoreForm({
</div>

<div className="space-y-4">
<Label>Photos</Label>
<Label>Photos *</Label>
<input
ref={fileInputRef}
type="file"
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/app/user/locations/edit/[id]/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ const EditStoreForm = ({
const handleSubmit = useCallback(
(event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

if (keptExistingPhotos.length === 0 && selectedImages.length === 0) {
toast.error('Please add at least one photo');
return;
}

const formData = new FormData(event.currentTarget);
const latInput = latitudeRef.current?.value ?? '';
const lngInput = longitudeRef.current?.value ?? '';
Expand Down Expand Up @@ -731,7 +737,7 @@ const EditStoreForm = ({
</div>

<div className="space-y-4">
<Label>Photos</Label>
<Label>Photos *</Label>

{keptExistingPhotos.length > 0 ? (
<div className="space-y-2">
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/user/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const addStoreFormSchema = z
.max(500, 'Store type description must be 500 characters or less')
.optional(),
landmarks: z.string().optional(),
photos: z.array(z.string()).optional(),
photos: z.array(z.string()).min(1, 'At least one photo is required'),
latitude: z.number(),
longitude: z.number(),
phase_id: z.string().optional(),
Expand Down Expand Up @@ -40,6 +40,7 @@ export type AddStoreFormData = z.infer<typeof addStoreFormSchema>;

export const editStoreFormSchema = addStoreFormSchema.partial().extend({
id: z.string().min(1, 'Store ID is required'),
photos: z.array(z.string()).min(1, 'At least one photo is required'),
});

export type EditStoreFormData = z.infer<typeof editStoreFormSchema>;