diff --git a/src/apiClient/approvals.ts b/src/apiClient/approvals.ts index b343b24..1918b61 100644 --- a/src/apiClient/approvals.ts +++ b/src/apiClient/approvals.ts @@ -13,6 +13,8 @@ export type Approval = { items: ApprovalItem[]; }; +export type RenterApproval = Omit; + interface GearItem { id: string; type: GearTypeWithShorthand; diff --git a/src/components/AddApprovalLink.tsx b/src/components/AddApprovalLink.tsx new file mode 100644 index 0000000..ea979ff --- /dev/null +++ b/src/components/AddApprovalLink.tsx @@ -0,0 +1,11 @@ +import { Link } from "react-router-dom"; + +export function AddApprovalLink({ personId }: { personId?: string }) { + const to = + personId == null ? "/add-approval" : `/add-approval?personId=${personId}`; + return ( + + + + ); +} diff --git a/src/components/ApprovalItemsList.tsx b/src/components/ApprovalItemsList.tsx new file mode 100644 index 0000000..a88efae --- /dev/null +++ b/src/components/ApprovalItemsList.tsx @@ -0,0 +1,32 @@ +import { ApprovalItem } from "src/apiClient/approvals"; + +import { GearLink } from "./GearLink"; + +/** + * Renders a list of approval items (gear types or specific gear items) + */ +export function ApprovalItemsList({ items }: { items: ApprovalItem[] }) { + return ( + + ); +} diff --git a/src/components/PersonSelect.tsx b/src/components/PersonSelect.tsx index c3960a1..656196e 100644 --- a/src/components/PersonSelect.tsx +++ b/src/components/PersonSelect.tsx @@ -1,8 +1,8 @@ -import { PersonSummary } from "src/apiClient/people"; import { countBy } from "lodash"; import { useState } from "react"; -import { usePeopleList } from "src/redux/api"; +import { PersonSummary } from "src/apiClient/people"; +import { useGetPersonQuery, usePeopleList } from "src/redux/api"; import { Select } from "./Select"; import { useDebounce } from "./useDebounce"; @@ -20,14 +20,26 @@ export function PersonSelect({ value, onChange, className, invalid }: Props) { const { personList, isFetching } = usePeopleList({ q: query, }); + const { data: selectedPerson } = useGetPersonQuery(value ?? "", { + skip: value == null, + }); const getName = (person: PersonSummary) => `${person.firstName} ${person.lastName}`; const namesCount = countBy(personList, getName); + const listWithSelection = + personList == null + ? [] + : selectedPerson == null + ? personList + : personList.some((p) => p.id === value) + ? personList + : [...personList, selectedPerson]; + const options = - personList?.map((person) => { + listWithSelection?.map((person) => { const name = getName(person); const fullName = namesCount[name] > 1 ? `${name} (${person.email})` : name; @@ -38,7 +50,8 @@ export function PersonSelect({ value, onChange, className, invalid }: Props) { }; }) ?? []; - const selectedOption = options.find((o) => o.id === value); + // We want == rather than ===, there is some type mess here + const selectedOption = options.find((o) => o.id == value); return (