import React from "react"; import WarningAmberOutlinedIcon from "@mui/icons-material/WarningAmberOutlined"; import { Box, Button, Stack, TableBody, ToggleButton, ToggleButtonGroup } from "@mui/material"; import ActionBar from "../../../../components/ActionBar"; import { Header } from "../../../../components/Header"; import { Page } from "../../../../components/Page"; import SearchBar from "../../../../components/SearchBar"; import { Table } from "../../../../components/Table"; import { TableCell } from "../../../../components/Table/TableCell"; import TableHead from "../../../../components/Table/TableHead"; import TableHeading from "../../../../components/Table/TableHeading"; import { NavigatingTableRow } from "../../../../components/Table/TableRow"; import TableCard from "../../../../components/TableCard"; import { TitleBar } from "../../../../components/TitleBar"; import Content, { ContentWrapperWithActionBar } from "../../../../containers/Content"; import { useI18n } from "../../../../contexts/I18nContext"; import { useRouter } from "../../../../contexts/RouterContext"; import { useUser } from "../../../../contexts/UserContext"; import { LimitOffset, PageComponent } from "../../../../types"; import { formatCustomerName } from "../../../../util/format_string"; import { hasPermission } from "../../../../util/has_permission"; import { CustomerType, MemberList } from "../../types/member"; import { CustomerTypeIcon } from "../../utils/customerTypeIcon"; type CustomerTypeFilter = CustomerType | "ALL"; const MemberListPage: PageComponent> = ({ data }) => { const { t } = useI18n(); const { navigate } = useRouter(); const { user } = useUser(); const defaultSearch = new URLSearchParams(window.location.search).get("search") ?? ""; const defaultCustomerType = new URLSearchParams(window.location.search).get("customer_type"); const [searchValue, setSearchValue] = React.useState(defaultSearch); const [customerTypeFilter, setCustomerTypeFilter] = React.useState( defaultCustomerType === CustomerType.PRIVATE || defaultCustomerType === CustomerType.COMPANY ? defaultCustomerType : "ALL", ); const customerTypeFilterCount = customerTypeFilter === "ALL" ? undefined : 1; const navigateWithFilters = React.useCallback( (searchInput: string, customerType: CustomerTypeFilter) => { const query: Record = {}; if (searchInput !== "") { query.search = searchInput; } if (customerType !== "ALL") { query.customer_type = customerType; } navigate("member.member:list", { query, replace: true, }); }, [navigate], ); const handleCustomerTypeChange = ( _: React.MouseEvent, customerType: CustomerTypeFilter | null, ) => { if (customerType === null) return; setCustomerTypeFilter(customerType); navigateWithFilters(searchValue, customerType); }; return (
setSearchValue(input)} onSubmit={(input) => { setSearchValue(input); navigateWithFilters(input, customerTypeFilter); }} />
{t("Number")} {t("Name")} {t("Phone")} {t("Email")} {t("Site")} {t("All")} {t("Private")} {t("Company")} } popoverLabel={customerTypeFilterCount} > {t("Type")} {data?.results.map((member) => ( {member.number} {CustomerTypeIcon(member.customer_type)} {formatCustomerName(member)} {member.phone ?? "—"} {member.email} {member.site_code} {member.customer_type} {!member.is_valid_customer ? ( ) : null} ))}
{hasPermission(user, "member.add_member") && ( )}
); }; export default MemberListPage;