Fixed location editor
This commit is contained in:
1 parent
4869756957
commit
ac4b50293e
3 files changed
+38
-22
No files matched your search
@@ -3745,6 +3745,7 @@ app.post('/api/birds', requireAuth, requireWriteAccess, requireWorkspaceRole(['o
|
|||||||
toWorkspaceId: req.auth!.workspace.id,
|
toWorkspaceId: req.auth!.workspace.id,
|
||||||
locationLabel: bird!.location_label,
|
locationLabel: bird!.location_label,
|
||||||
locationDetails: bird!.location_details,
|
locationDetails: bird!.location_details,
|
||||||
|
eventDate: emptyToNull(parsed.data.locationDate),
|
||||||
createdByUserId: req.auth!.user.id,
|
createdByUserId: req.auth!.user.id,
|
||||||
});
|
});
|
||||||
res.status(201).json({ bird: normalizeBird(bird!) });
|
res.status(201).json({ bird: normalizeBird(bird!) });
|
||||||
@@ -4124,6 +4125,7 @@ app.put('/api/birds/:birdId', requireAuth, requireWriteAccess, requireWorkspaceR
|
|||||||
toWorkspaceId: req.auth!.workspace.id,
|
toWorkspaceId: req.auth!.workspace.id,
|
||||||
locationLabel: bird.location_label,
|
locationLabel: bird.location_label,
|
||||||
locationDetails: bird.location_details,
|
locationDetails: bird.location_details,
|
||||||
|
eventDate: emptyToNull(parsed.data.locationDate),
|
||||||
createdByUserId: req.auth!.user.id,
|
createdByUserId: req.auth!.user.id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ export const locationSearchSchema = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const birdSchema = z.object({
|
export const birdSchema = z.object({
|
||||||
|
locationDate: dateStringSchema.optional().or(z.literal('')),
|
||||||
name: z.string().trim().min(1).max(120),
|
name: z.string().trim().min(1).max(120),
|
||||||
tagId: z.string().trim().max(80).optional().or(z.literal('')),
|
tagId: z.string().trim().max(80).optional().or(z.literal('')),
|
||||||
species: z.string().trim().min(1).max(120),
|
species: z.string().trim().min(1).max(120),
|
||||||
|
|||||||
+35
-22
@@ -288,6 +288,7 @@ type FlockNoteFormState = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type BirdFormState = {
|
type BirdFormState = {
|
||||||
|
locationDate: string;
|
||||||
name: string;
|
name: string;
|
||||||
tagId: string;
|
tagId: string;
|
||||||
species: string;
|
species: string;
|
||||||
@@ -841,6 +842,7 @@ const VerifiedLocationSearchField = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const emptyBirdForm: BirdFormState = {
|
const emptyBirdForm: BirdFormState = {
|
||||||
|
locationDate: '',
|
||||||
name: '',
|
name: '',
|
||||||
tagId: '',
|
tagId: '',
|
||||||
species: '',
|
species: '',
|
||||||
@@ -1007,6 +1009,7 @@ const ProviderIcon = ({ providerKey }: { providerKey: AuthProvider['providerKey'
|
|||||||
const sortBirdsByName = (nextBirds: Bird[]) => [...nextBirds].sort((left, right) => left.name.localeCompare(right.name));
|
const sortBirdsByName = (nextBirds: Bird[]) => [...nextBirds].sort((left, right) => left.name.localeCompare(right.name));
|
||||||
|
|
||||||
const toBirdForm = (bird: Bird): BirdFormState => ({
|
const toBirdForm = (bird: Bird): BirdFormState => ({
|
||||||
|
locationDate: '',
|
||||||
name: bird.name,
|
name: bird.name,
|
||||||
tagId: bird.tagId ?? '',
|
tagId: bird.tagId ?? '',
|
||||||
species: bird.species,
|
species: bird.species,
|
||||||
@@ -4302,7 +4305,7 @@ function App() {
|
|||||||
const response = await apiFetch(isEditing ? `/birds/${editingBirdId}` : '/birds', authToken, {
|
const response = await apiFetch(isEditing ? `/birds/${editingBirdId}` : '/birds', authToken, {
|
||||||
method,
|
method,
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ ...birdForm, hatchDay: birdForm.dateOfBirth, locationLabel }),
|
body: JSON.stringify({ ...birdForm, hatchDay: birdForm.dateOfBirth, locationLabel, locationDate: birdForm.locationDate || getLocalDateString() }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -7130,27 +7133,6 @@ function App() {
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
<div className="settings-inline-header wide-field">
|
|
||||||
<p className="eyebrow">Location</p>
|
|
||||||
<h3>Mappable location</h3>
|
|
||||||
</div>
|
|
||||||
<VerifiedLocationSearchField
|
|
||||||
label="Location"
|
|
||||||
location={birdForm.locationDetails}
|
|
||||||
fallbackLabel={birdForm.locationLabel}
|
|
||||||
searchState={birdLocationSearch}
|
|
||||||
onSearchStateChange={setBirdLocationSearch}
|
|
||||||
onSearch={() => searchVerifiedLocations(birdLocationSearch, setBirdLocationSearch)}
|
|
||||||
onSelect={(location) => {
|
|
||||||
const locationLabel = formatVerifiedLocationLabel(location);
|
|
||||||
setBirdForm({ ...birdForm, locationDetails: location, locationLabel });
|
|
||||||
setBirdLocationSearch({ ...emptyLocationSearchState, query: locationLabel });
|
|
||||||
}}
|
|
||||||
onClear={() => {
|
|
||||||
setBirdForm({ ...birdForm, locationDetails: emptyVerifiedLocationDetails, locationLabel: '' });
|
|
||||||
setBirdLocationSearch(emptyLocationSearchState);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div className="segmented-field wide-field">
|
<div className="segmented-field wide-field">
|
||||||
<span>Gender</span>
|
<span>Gender</span>
|
||||||
<div className="segmented-control" role="radiogroup" aria-label="Bird gender">
|
<div className="segmented-control" role="radiogroup" aria-label="Bird gender">
|
||||||
@@ -7289,6 +7271,37 @@ function App() {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
<div className="settings-inline-header wide-field">
|
||||||
|
<p className="eyebrow">Location</p>
|
||||||
|
<h3>Mappable location</h3>
|
||||||
|
</div>
|
||||||
|
<VerifiedLocationSearchField
|
||||||
|
label="Location"
|
||||||
|
location={birdForm.locationDetails}
|
||||||
|
fallbackLabel={birdForm.locationLabel}
|
||||||
|
searchState={birdLocationSearch}
|
||||||
|
onSearchStateChange={setBirdLocationSearch}
|
||||||
|
onSearch={() => searchVerifiedLocations(birdLocationSearch, setBirdLocationSearch)}
|
||||||
|
onSelect={(location) => {
|
||||||
|
const locationLabel = formatVerifiedLocationLabel(location);
|
||||||
|
setBirdForm({ ...birdForm, locationDetails: location, locationLabel });
|
||||||
|
setBirdLocationSearch({ ...emptyLocationSearchState, query: locationLabel });
|
||||||
|
}}
|
||||||
|
onClear={() => {
|
||||||
|
setBirdForm({ ...birdForm, locationDetails: emptyVerifiedLocationDetails, locationLabel: '' });
|
||||||
|
setBirdLocationSearch(emptyLocationSearchState);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<label>
|
||||||
|
Location date
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={birdForm.locationDate || getLocalDateString()}
|
||||||
|
onChange={(event) => setBirdForm({ ...birdForm, locationDate: event.target.value })}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<span className="muted">Date this location took effect. Used when adding a bird or changing its location.</span>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section className="settings-nested-card">
|
<section className="settings-nested-card">
|
||||||
|
|||||||
Reference in new issue
Block a user