extract select element

This commit is contained in:
Thomas Ruoff
2020-10-07 23:31:44 +02:00
parent f78b8ea772
commit e4082353e3
2 changed files with 71 additions and 67 deletions

40
components/select.tsx Normal file
View 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>
)
}

View File

@@ -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> value={rate}
<div className="relative"> onChange={(e) => setRate(e.target.value as MILAGE_RATES)}
<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" {milageRateOptions}
id="rate" </Select>
value={rate} <Select
onChange={( label="Status"
e: React.ChangeEvent<React.ElementRef<'select'>> value={status}
) => { onChange={(e) => setStatus(e.target.value as BILL_STATUS)}
setRate(e.target.value as MILAGE_RATES) >
}} {bookingStatusOptions}
> </Select>
{Object.values(MILAGE_RATES).map((rate) => {
return (
<option value={rate} key={rate}>
{getRateLabel(rate)} ({getMilageRateValue(rate)} EUR)
</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}
onChange={(
e: React.ChangeEvent<React.ElementRef<'select'>>
) => setStatus(e.target.value as BILL_STATUS)}
>
{Object.values(BILL_STATUS).map((status) => {
return (
<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 && (