import { Box, Button, Checkbox, FormControlLabel, Grid2 as Grid, MenuItem, Select } from "@mui/material"; import LibraCartAccess from "integrations/LibraCart/LibraCartAccess"; import { pond } from "protobuf-ts/pond"; import { useGlobalState } from "providers"; import { useLibraCartProxyAPI } from "providers/pond/libracartProxyAPI"; import React, { useEffect, useState } from "react"; import PageContainer from "./PageContainer"; export default function LibraCart() { const [currentOrg, setCurrentOrg] = useState(""); const libracartAPI = useLibraCartProxyAPI(); const [organizations, setOrganizations] = useState>(new Map()); const [dataOptions, setDataOptions] = useState([]); const [{ as }] = useGlobalState(); //load organizations for the user useEffect(() => { setCurrentOrg(""); libracartAPI .listAccounts(0, 0, as) .then(resp => { let tempOrgs: Map = new Map(); resp.data.accounts.forEach(org => { let organization = pond.LibraCartAccount.fromObject(org); tempOrgs.set(organization.key, organization); }); setOrganizations(tempOrgs); }) .catch(err => {}); }, [libracartAPI, as]); useEffect(() => { let organization = organizations.get(currentOrg); if (organization) { let currentOptions: pond.DataOption[] = organization.options ?? []; setDataOptions(currentOptions); } }, [currentOrg, organizations]); const updateOrgData = (checked: boolean, option: pond.DataOption) => { let currentOps: pond.DataOption[] = dataOptions; if (checked && !currentOps.includes(option)) { currentOps.push(option); } else if (!checked && currentOps.includes(option)) { currentOps.splice(currentOps.indexOf(option), 1); } setDataOptions([...currentOps]); }; const submit = () => { libracartAPI.updateAccount(currentOrg, dataOptions, as ?? undefined).then(resp => { //update the organization in the map to have the correct dataOptions let org = organizations.get(currentOrg); if (org) { org.options = dataOptions; } }); }; const fieldOptions = () => { return ( { //setFields(!fields); updateOrgData(checked, pond.DataOption.DATA_OPTION_DESTINATIONS); }} /> } /> Import your destinations for the option to link it to a bin ); }; return ( {fieldOptions()} ); }