-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of #12
- Loading branch information
Showing
7 changed files
with
174 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
webtool/frontend/src/components/company/company-display-edit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {FunctionComponent, useState} from "react" | ||
import {Company, Pilot} from "local4local" | ||
import {CompanyDisplay} from "./company-display.tsx"; | ||
import {CompanyForm} from "./company-form.tsx" | ||
|
||
export const CompanyDisplayEdit: FunctionComponent<{ | ||
pilot: Pilot, | ||
onChange: (pilot: Pilot) => void, | ||
}> = ({pilot, onChange}) => { | ||
const [selectedCompany, setSelectedCompany] = useState<Company | null>(null); | ||
return ( | ||
<> | ||
{pilot.companies.asJsReadonlyArrayView().map((it, i) => | ||
selectedCompany == it ? ( | ||
<CompanyForm | ||
key={"householdGroup_" + i} | ||
save={(newCompany: Company) => { | ||
onChange(pilot.replaceCompany(it, newCompany)) | ||
setSelectedCompany(null); | ||
}} | ||
hide={() => { | ||
setSelectedCompany(null); | ||
}} | ||
initialData={selectedCompany} | ||
/> | ||
) : ( | ||
<CompanyDisplay | ||
key={i} | ||
company={it} | ||
onEdit={() => { setSelectedCompany(it)}} | ||
toDelete={() => onChange(pilot.removeCompany(it))} | ||
/> | ||
) | ||
)} | ||
</> | ||
) | ||
} |
40 changes: 40 additions & 0 deletions
40
webtool/frontend/src/components/company/company-display.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {FunctionComponent} from "react" | ||
import {Card, DataList, Flex} from "@radix-ui/themes" | ||
import {Company} from "local4local" | ||
import {CompanyHeading} from "./company-heading.tsx" | ||
import {CardMenu} from "./../card-menu.tsx" | ||
|
||
const numberFormatter = new Intl.NumberFormat() | ||
|
||
export const CompanyDisplay: FunctionComponent<{ | ||
company: Company, | ||
onEdit: () => void, | ||
toDelete: () => void, | ||
}> = ({company, onEdit, toDelete}) => { | ||
return ( | ||
<Card> | ||
<Flex className="head-title"> | ||
<CompanyHeading /> | ||
<CardMenu onDelete={toDelete} onEdit={onEdit}/> | ||
</Flex> | ||
<DataList.Root> | ||
<DataList.Item> | ||
<DataList.Label minWidth="88px">Naam</DataList.Label> | ||
<DataList.Value>{company.name}</DataList.Value> | ||
</DataList.Item> | ||
<DataList.Item> | ||
<DataList.Label minWidth="88px">Bruto jaarverbruik</DataList.Label> | ||
<DataList.Value>{numberFormatter.format(company.annualElectricityConsumption_kWh)} kWh</DataList.Value> | ||
</DataList.Item> | ||
<DataList.Item> | ||
<DataList.Label minWidth="88px">Zonnepanelen</DataList.Label> | ||
<DataList.Value>{numberFormatter.format(company.pvInstalled_kWp)} kWp</DataList.Value> | ||
</DataList.Item> | ||
<DataList.Item> | ||
<DataList.Label minWidth="88px">Aantal laadpunten</DataList.Label> | ||
<DataList.Value>{company.chargePoints_n}</DataList.Value> | ||
</DataList.Item> | ||
</DataList.Root> | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {FormEvent, FunctionComponent} from "react" | ||
import {Company} from "local4local" | ||
import {Button, Card, Text} from "@radix-ui/themes" | ||
import {CompanyHeading} from "./company-heading.tsx" | ||
|
||
export const CompanyForm: FunctionComponent<{ | ||
initialData?: Company | null; | ||
save: (company: Company) => void, | ||
hide: () => void, | ||
}> = ({initialData, save, hide}) => { | ||
const onSubmit = (event: FormEvent) => { | ||
event.preventDefault() | ||
const form = event.target as HTMLFormElement | ||
const formData = new FormData(form); | ||
const householdGroup = new Company( | ||
formData.get("name") as string, | ||
parseFloat(formData.get("annualElectricityConsumption_kWh") as string) || 0, | ||
parseFloat(formData.get("pvInstalled_kWp") as string) || 0, | ||
parseInt(formData.get("chargePoints_n") as string) || 0, | ||
); | ||
save(householdGroup); | ||
hide(); | ||
}; | ||
|
||
return ( | ||
<Card className="form-box"> | ||
<CompanyHeading /> | ||
<form onSubmit={onSubmit}> | ||
<div className="radix-grid"> | ||
<label className="form-label" htmlFor="name">Naam</label> | ||
<input className="form-input" type="text" id="name" name="name" defaultValue={initialData?.name} /> | ||
</div> | ||
<div className="radix-grid"> | ||
<label className="form-label" htmlFor="annualElectricityConsumption_kWh">Bruto jaarverbruik | ||
[kWh]</label> | ||
<input | ||
className="form-input" | ||
type="number" | ||
id="annualElectricityConsumption_kWh" | ||
name="annualElectricityConsumption_kWh" | ||
defaultValue={initialData?.annualElectricityConsumption_kWh} | ||
min={0} /> | ||
</div> | ||
<div className="form-message"> | ||
<Text> | ||
Verbruik achter de meter. Inclusief verbruik van eigen opwek. Exclusief verbruik van laadpalen. | ||
</Text> | ||
</div> | ||
<div className="radix-grid"> | ||
<label className="form-label" htmlFor="pvInstalled_kWp">Zonnepanelen [kWp]</label> | ||
<input className="form-input" type="number" id="pvInstalled_kWp" name="pvInstalled_kWp" | ||
defaultValue={initialData?.pvInstalled_kWp} min={0} /> | ||
</div> | ||
<div className="radix-grid"> | ||
<label className="form-label" htmlFor="chargePoints_n">Aantal laadpunten</label> | ||
<input className="form-input" type="number" id="chargePoints_n" name="chargePoints_n" | ||
defaultValue={initialData?.chargePoints_n} min={0} /> | ||
</div> | ||
<Button onClick={hide} style={{marginRight: '10px'}} highContrast variant="soft">Annuleren</Button> | ||
<Button type="submit">Opslaan</Button> | ||
</form> | ||
</Card> | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
webtool/frontend/src/components/company/company-heading.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Heading} from "@radix-ui/themes" | ||
import {HiOutlineBuildingOffice2} from "react-icons/hi2" | ||
|
||
export const CompanyHeading = () => ( | ||
<Heading as="h3" style={{paddingBottom: ".5rem"}}> | ||
<HiOutlineBuildingOffice2 /> | ||
| ||
Bedrijf | ||
</Heading> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters