mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
extract select element
This commit is contained in:
40
components/select.tsx
Normal file
40
components/select.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export default function Select({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
label: string
|
||||||
|
value: string
|
||||||
|
onChange: (e: React.ChangeEvent<HTMLSelectElement>) => void
|
||||||
|
children: React.ReactNode
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="fsw">
|
||||||
|
<div className="fs">
|
||||||
|
<label className="flabel">{label}</label>
|
||||||
|
<div className="relative">
|
||||||
|
<select
|
||||||
|
className="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
||||||
|
id="rate"
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</select>
|
||||||
|
<div className="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
|
||||||
|
<svg
|
||||||
|
className="fill-current h-4 w-4"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
>
|
||||||
|
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react'
|
|||||||
import Footer from '../../../components/footer'
|
import Footer from '../../../components/footer'
|
||||||
import Header from '../../../components/header'
|
import Header from '../../../components/header'
|
||||||
import Input from '../../../components/input'
|
import Input from '../../../components/input'
|
||||||
|
import Select from '../../../components/select'
|
||||||
import { AdditionalCosts, BillDocument } from '../../../db/bill'
|
import { AdditionalCosts, BillDocument } from '../../../db/bill'
|
||||||
import { BookingDocument } from '../../../db/booking'
|
import { BookingDocument } from '../../../db/booking'
|
||||||
import {
|
import {
|
||||||
@@ -13,6 +14,22 @@ import {
|
|||||||
import { getBookingByUUID } from '../../../db/index'
|
import { getBookingByUUID } from '../../../db/index'
|
||||||
import { dateFormatFrontend } from '../../../helpers/date'
|
import { dateFormatFrontend } from '../../../helpers/date'
|
||||||
|
|
||||||
|
const milageRateOptions = Object.values(MILAGE_RATES).map((rate) => {
|
||||||
|
return (
|
||||||
|
<option value={rate} key={rate}>
|
||||||
|
{getRateLabel(rate)} ({getMilageRateValue(rate)} EUR)
|
||||||
|
</option>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const bookingStatusOptions = Object.values(BILL_STATUS).map((status) => {
|
||||||
|
return (
|
||||||
|
<option value={status} key={status}>
|
||||||
|
{getBillStatusLabel(status)}
|
||||||
|
</option>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
const {
|
const {
|
||||||
res,
|
res,
|
||||||
@@ -177,73 +194,20 @@ export default function BillPage({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<Input label="Gefahren" name="milage" readOnly value={milage} />
|
<Input label="Gefahren" name="milage" readOnly value={milage} />
|
||||||
<div className="fsw">
|
<Select
|
||||||
<div className="fs">
|
label="Rate"
|
||||||
<label className="flabel">Rate</label>
|
|
||||||
<div className="relative">
|
|
||||||
<select
|
|
||||||
className="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
|
||||||
id="rate"
|
|
||||||
value={rate}
|
value={rate}
|
||||||
onChange={(
|
onChange={(e) => setRate(e.target.value as MILAGE_RATES)}
|
||||||
e: React.ChangeEvent<React.ElementRef<'select'>>
|
|
||||||
) => {
|
|
||||||
setRate(e.target.value as MILAGE_RATES)
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{Object.values(MILAGE_RATES).map((rate) => {
|
{milageRateOptions}
|
||||||
return (
|
</Select>
|
||||||
<option value={rate} key={rate}>
|
<Select
|
||||||
{getRateLabel(rate)} ({getMilageRateValue(rate)} EUR)
|
label="Status"
|
||||||
</option>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</select>
|
|
||||||
<div className="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
|
|
||||||
<svg
|
|
||||||
className="fill-current h-4 w-4"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
viewBox="0 0 20 20"
|
|
||||||
>
|
|
||||||
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="fsw">
|
|
||||||
<div className="fs">
|
|
||||||
<label className="flabel">Status</label>
|
|
||||||
<div className="relative">
|
|
||||||
<select
|
|
||||||
className="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500"
|
|
||||||
id="rate"
|
|
||||||
value={status}
|
value={status}
|
||||||
onChange={(
|
onChange={(e) => setStatus(e.target.value as BILL_STATUS)}
|
||||||
e: React.ChangeEvent<React.ElementRef<'select'>>
|
|
||||||
) => setStatus(e.target.value as BILL_STATUS)}
|
|
||||||
>
|
>
|
||||||
{Object.values(BILL_STATUS).map((status) => {
|
{bookingStatusOptions}
|
||||||
return (
|
</Select>
|
||||||
<option value={status} key={status}>
|
|
||||||
{getBillStatusLabel(status)}
|
|
||||||
</option>
|
|
||||||
)
|
|
||||||
})}
|
|
||||||
</select>
|
|
||||||
<div className="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
|
|
||||||
<svg
|
|
||||||
className="fill-current h-4 w-4"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
viewBox="0 0 20 20"
|
|
||||||
>
|
|
||||||
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Input label="Summe" name="milage" readOnly value={total} />
|
<Input label="Summe" name="milage" readOnly value={total} />
|
||||||
</div>
|
</div>
|
||||||
{storingError && (
|
{storingError && (
|
||||||
|
|||||||
Reference in New Issue
Block a user