Skip to content

Commit

Permalink
UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
n1kPLV committed Jul 28, 2023
1 parent a5405a6 commit 97dc50c
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions Website/src/app/management/vehicles/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const fetcher = async ([url, track_id]: [url: string, track_id: number]) => {
}
const res_1 = await res;
const res_2: VehicleList = await res_1.json();
res_2.push({uid: NaN, name: '[Neues Fahrzeug hinzufügen]', typeId: 0, trackerIds: []});
// Add a placeholder vehicle
res_2.unshift({uid: NaN, name: '[Neues Fahrzeug hinzufügen]', typeId: 0, trackerIds: []});
return res_2;
};

Expand Down Expand Up @@ -95,9 +96,32 @@ export default function VehicleManagement({trackID, vehicleTypes}: {

}

const deleteVehicle: FormEventHandler = (e) => {
const deleteVehicle: FormEventHandler = async (e) => {
e.preventDefault();
setError('gelöscht!');
const vehicle = vehicleList && getVehicleByUid(vehicleList, Number.parseInt(selVehicle, 10));

const confirmation = confirm(`Möchten Sie das Fahrzeug ${vehicle?.name} wirklich entfernen?`)

if (confirmation) {
try {
const result = await fetch(`/webapi/vehicles/delete/${selVehicle}`, {
method: 'DELETE'
})
if (result.ok) {
setSuccess(true);
setError(undefined)
// invalidate cached result for key ['/webapi/vehicles/list/', trackID]
mutate();
} else {
if (result.status == 401)
setError('Authorisierungsfehler: Sind Sie angemeldet?')
if (result.status >= 500 && result.status < 600)
setError(`Serverfehler ${result.status} ${result.statusText}`)
}
} catch (e) {
setError(`Connection Error: ${e}`)
}
}
}

// select different vehicle function
Expand Down Expand Up @@ -193,7 +217,7 @@ export default function VehicleManagement({trackID, vehicleTypes}: {
<option value={''} disabled={true}>[Bitte auswählen]</option>
{vehicleTypes.map((type) => <option key={type.uid} value={type.uid}>{type.name}</option>)}
</select>
{vehicTrackers.map((uid, idx, list) => (<>
{vehicTrackers.map((uid, idx, ) => (<>
<label htmlFor={`vehicTracker${idx}`} className={'col-span-3'}>{idx == 0
? <>Tracker<span
className="sr-only"> Nummer {`${idx + 1}`}</span>:</>
Expand Down

0 comments on commit 97dc50c

Please sign in to comment.