Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | 29x 601x 601x 601x 601x 601x 3x 3x 29x 29x | import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import { XIcon } from "@phosphor-icons/react";
import GiveButton from "@shared/Button/GiveButton";
import GiveIconButton from "@shared/IconButton/GiveIconButton";
import {
SidePanelFooterContainer,
SidePanelHeaderBase,
} from "@shared/SidePanel/components/SidePanelHeader/SidePanelHeader";
import { SidePanelContainerWrapper } from "@shared/SidePanel/SidePanelAtoms";
import GiveText from "@shared/Text/GiveText";
import { styled } from "@theme/v2/Provider";
import { FormProvider } from "react-hook-form";
import { isEmpty } from "lodash";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import { FilterPagesEnum } from "../constants";
import useGeneralFilters from "../hooks/useGeneralFilters";
import FilterModalContent from "./FilterModalContent";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
const GiveFilterModalContent = ({
filterPage,
handleClose,
productId,
}: {
filterPage: FilterPagesEnum;
handleClose?: () => void;
/** Scopes an entity-specific filter page — see useGetFilterSectionPerPage. */
productId?: string;
}) => {
const { isMobileView } = useCustomThemeV2();
const { open } = useNiceModal();
const {
areObjectsSame,
filterSections,
methods,
handleSubmit,
isValid,
handleClearFilters,
resetModal,
errorsForCustomChip,
} = useGeneralFilters({
filterPage,
open,
productId,
// the filter modal should close on apply only in mobile view
handleClose: isMobileView ? handleClose : undefined,
});
const isCustomChipError = !isEmpty(errorsForCustomChip);
return (
<SidePanelContainerWrapper
sx={{
display: "flex",
flexDirection: "column",
height: "100%",
}}
>
<SidePanelHeaderBase
leftItems={<GiveText variant="bodyM">Filters</GiveText>}
rightItems={
<GiveIconButton
data-testid="panel-x-icon"
Icon={XIcon}
variant="ghost"
onClick={() => {
resetModal();
handleClose?.();
}}
size="small"
/>
}
/>
<FormProvider {...methods}>
<FormContainer onSubmit={methods.handleSubmit(handleSubmit)}>
<ContentWrapper>
<FilterModalContent filterSections={filterSections} />
</ContentWrapper>
<SidePanelFooterContainer>
<>
{!areObjectsSame && (
<GiveButton
label="Clear All Filters"
variant="ghost"
color="destructive"
size="large"
onClick={handleClearFilters}
disabled={areObjectsSame}
data-testid="clear-all-filter-button"
/>
)}
<GiveTooltip
title={errorsForCustomChip?.[0]}
disableHoverListener={!isCustomChipError}
disableTouchListener={!isCustomChipError}
disableFocusListener={!isCustomChipError}
sx={{
width: "unset !important",
"&.MuiStack-root": {
width: "unset",
},
}}
>
<GiveButton
disabled={!isValid || areObjectsSame || isCustomChipError}
label="Apply"
variant="filled"
size="large"
type="submit"
sx={{
width: "unset",
}}
data-testid="Apply-all-filter-button"
/>
</GiveTooltip>
</>
</SidePanelFooterContainer>
</FormContainer>
</FormProvider>
</SidePanelContainerWrapper>
);
};
export default GiveFilterModalContent;
const FormContainer = styled("form")({
display: "flex",
flexDirection: "column",
flexGrow: 1,
minHeight: 0,
});
const ContentWrapper = styled("div")({
flexGrow: 1,
overflowY: "auto",
minHeight: 0,
});
|