Files
TREK/client/src/components/Collections/PlaceEditForm.tsx
T
Maurice e539860530 fix(quality): resolve reliability findings on dev
The Sonar quality gate rated new code D. Preserve focus and keyboard interaction through native controls and shared dialog behavior. Replace ambiguous regex scans with bounded parsing and make numeric coercion and initialization explicit.
2026-12-01 21:06:05 +01:00

93 lines
3.1 KiB
TypeScript

import { MapPin } from 'lucide-react';
import React from 'react';
import type { Category, TranslationFn } from '../../types';
import { focusRevealedEditor } from '../shared/dialogFocus';
import { NumericInput } from '../shared/NumericInput';
import CategoryTileMenu from './CategoryTileMenu';
import type { PlaceEditState } from './usePlaceEdit';
/**
* The edit form of a place of All places in the desktop dialog: the name with
* its category, the address, the position and the description. The change is
* made on every copy of the place in the reader's lists and trips they may edit.
*/
export default function PlaceEditForm({
edit,
categories,
t,
}: {
edit: PlaceEditState;
categories: Category[];
t: TranslationFn;
}): React.ReactElement | null {
const { draft, target } = edit;
if (!draft || !target) return null;
return (
<div className="col-detail-edit">
<div className="col-detail-field">
<div className="col-detail-label">{t('common.name')}</div>
<div className="flex items-center gap-2.5">
{categories.length > 0 && (
<CategoryTileMenu
categories={categories}
value={draft.categoryId}
onChange={(id) => edit.set('categoryId', id)}
size={36}
t={t}
/>
)}
<input
ref={focusRevealedEditor}
value={draft.name}
onChange={(e) => edit.set('name', e.target.value)}
aria-label={t('common.name')}
className="col-detail-input min-w-0 flex-1"
/>
</div>
</div>
<div className="col-detail-field">
<div className="col-detail-label">
<MapPin size={12} /> {t('places.formAddress')}
</div>
<input
value={draft.address}
onChange={(e) => edit.set('address', e.target.value)}
placeholder={t('places.formAddressPlaceholder')}
className="col-detail-input"
/>
</div>
<div className="col-detail-field">
<div className="col-detail-label">
<MapPin size={12} /> {t('collections.coordinates')}
</div>
<div className="col-detail-link-row">
<NumericInput
mode="signed"
value={draft.lat}
onValueChange={(v) => edit.set('lat', v)}
placeholder={t('places.formLat')}
className="col-detail-input flex-1"
/>
<NumericInput
mode="signed"
value={draft.lng}
onValueChange={(v) => edit.set('lng', v)}
placeholder={t('places.formLng')}
className="col-detail-input flex-1"
/>
</div>
</div>
<div className="col-detail-field">
<div className="col-detail-label">{t('collections.description')}</div>
<textarea
value={draft.description}
onChange={(e) => edit.set('description', e.target.value)}
rows={5}
placeholder={t('collections.descriptionPlaceholder')}
className="col-detail-textarea"
/>
</div>
</div>
);
}