Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "wordpress-plugins/real-cookie-banner/src/public/ts/components/config/scanner/presetSelector"

Index

Type aliases

ScannerPresetAdditionalData

ScannerPresetAdditionalData: { scanned: ScannerResultPreset["data"]["scanned"] }

Type declaration

  • scanned: ScannerResultPreset["data"]["scanned"]

Variables

Const ScannerPresetSelector

ScannerPresetSelector: FC<{}> = observer(() => {const [busy, setBusy] = useState(false);const { scannerStore, cookieStore } = useStores();const { resultPresets, busyResultPresets } = scannerStore;const { remaining } = useScannerProgress();const { essentialGroup } = cookieStore;const [hasModalOpen, setHasModalOpen] = useState(false);// Initially fetch the cookie groups as we need the ID of the essential groupuseEffect(() => {cookieStore.fetchGroups();}, []);const handleOnSelect: ComponentProps<typeof PresetSelector>["onSelect"] = useCallback(async (attributes) => {if (hasModalOpen || !attributes || busy) {return;}setBusy(true);const { identifier: blockerIdentifier } = attributes;const preset = scannerStore.resultPresets.get(blockerIdentifier);// Always navigate back to the scanner resultsconst navigateAfterCreation = `navigateAfterCreation=${encodeURIComponent("#scanner")}`;try {await preset.fetchAttributes();} catch (e) {// It is only a servicesetTimeout(() =>(window.location.href = `#/cookies/${essentialGroup?.key}/new?force=${blockerIdentifier}&${navigateAfterCreation}`),0);setBusy(false);return;}const {data: { hidden },attributes: {serviceTemplates: [firstCookie]}} = preset;if (!firstCookie) {return;}if (typeof firstCookie !== "number" || hidden) {if (hidden) {// It is a hidden content blocker, so we can only create a servicesetTimeout(() =>(window.location.href = `#/cookies/${essentialGroup?.key}/new?force=${blockerIdentifier}&${navigateAfterCreation}`),0);} else if (typeof firstCookie !== "number") {// Service (Cookie) does not exist -> directly navigate to the service and force content blocker to be createdconst { identifier: cookieIdentifier } = firstCookie;setTimeout(() =>(window.location.href = `#/cookies/${essentialGroup?.key}/new?force=${cookieIdentifier}&attributes=${JSON.stringify({createContentBlocker:firstCookie.attributes.group?.toLowerCase() !==essentialGroup?.data.name.toLowerCase(),createContentBlockerId: blockerIdentifier})}&${navigateAfterCreation}`),0);}} else {// Service (Cookie) already exists -> directly navigate to the content blockersetTimeout(() => (window.location.href = `#/blocker/new?force=${blockerIdentifier}&${navigateAfterCreation}`),0);}setBusy(false);},[busy, hasModalOpen, essentialGroup]);return (<ConfigContent><Divider>{__("Services, for which you should obtain consent")}</Divider><PresetSelector<ScannerPresetAdditionalData>type="contentBlocker"presets={Array.from(resultPresets.values()).map(// eslint-disable-next-line @typescript-eslint/no-unused-vars({ data: { logoFile, ...preset }, fullLogoUrl }) => ({...preset,logoUrl: fullLogoUrl}))}fetchingPresets={(busyResultPresets && /* Do not show loading indicator while scanning */ !remaining) || busy}onSelect={handleOnSelect}renderActions={useCallback((props) => {const { identifier, version, attributes_name, scanned, tier } = props;return [<akey="create-now"onClick={() =>tier !== "pro" &&handleOnSelect({identifier,version,attributes_name})}>{__("Create now")}</a>,scanned && (<ScannerPresetCardActionOpenExternalUrlsTable{...props}key="table"onVisibleChange={setHasModalOpen}/>)].filter(Boolean);}, [])}showSearch={false}showDisabled={false}showHidden/></ConfigContent>);})

Generated using TypeDoc