Skip to content
Draft
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
2 changes: 1 addition & 1 deletion backend/db/app_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func (a *AppDB) AddLocation(ctx context.Context, location *structs.Location) err
$19, $20, $21, $22, $23, $24, $25, $26,
$27, $28, $29, $30, $31, $32
)
ON CONFLICT (google_id) WHERE active = TRUE
ON CONFLICT (google_id) WHERE active = TRUE AND google_id IS NOT NULL
DO UPDATE SET
owner_id = EXCLUDED.owner_id,
name = EXCLUDED.name,
Expand Down
2 changes: 1 addition & 1 deletion backend/handlers/app_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ func (a *AppService) AddLocation(w http.ResponseWriter, r *http.Request) {
location.OwnerID = *userDid
err = a.db.AddLocation(r.Context(), location)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
a.logger.Logf("invalid location body: %s", err.Error())
http.Error(w, "Unable to submit merchant application.", http.StatusBadRequest)
return
}

Expand Down
17 changes: 12 additions & 5 deletions frontend/components/merchant/merchant-approval-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,22 @@ export function MerchantApprovalForm() {
service_stations: Number(serviceStations),
tablet_model: tabletModel === "Other" ? tabletModelOther : tabletModel,
messaging_service: messagingService === "Other" ? messagingServiceOther : messagingService,
payment_wallets: [],
reference: reference,
}

setIsSubmitting(true)
await addLocation(newLocation)
setSearchKey(prev => prev + 1)
setIsSubmitting(false);
resetForm()
router.replace("/map")
setError(null)
try {
await addLocation(newLocation)
setSearchKey(prev => prev + 1)
resetForm()
router.replace("/map")
} catch (error) {
setError(error instanceof Error ? error.message : "Unable to submit merchant application.")
} finally {
setIsSubmitting(false)
}
}

return (
Expand Down
8 changes: 5 additions & 3 deletions frontend/context/LocationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ export default function LocationProvider({ children }: { children: ReactNode })
body: JSON.stringify(location)
})
if(res.status != 201) {
throw new Error("error adding new location, from controller")
const message = (await res.text()).trim()
throw new Error(message || "Unable to submit merchant application.")
}
setUserLocationsRef.current((currentLocations) => [...currentLocations, location])
setMapLocationsStatus("available")
}
catch {
catch (error) {
setMapLocationsStatus("unavailable")
console.error("error adding new location")
console.error("error adding new location", error)
throw error
}
}, [])

Expand Down