Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "wordpress-plugins/real-cookie-banner/src/public/ts/components/config/cookies/form"

Index

Variables

Variables

Const CookieEditForm

CookieEditForm: FC<{ navigateAfterCreation?: boolean | string; onCreated?: (model: CookieModel) => void; overwriteAttributes?: CookiePreset["attributes"] & { createContentBlocker?: boolean; createContentBlockerId?: string }; preset?: { identifier: string; version: number }; scrollToTop?: boolean }> = observer(({ preset, overwriteAttributes, navigateAfterCreation = true, scrollToTop = true, onCreated }) => {const {routeGroup: { group, link },cookie,id,queried,fetched} = useRouteCookie();const history = useHistory();const {cookieStore,optionStore: {tcf,ePrivacyUSA,consentForwarding,setCookiesViaManager,hasManager,others: { useEncodedStringForScriptInputs, isPro, activePlugins }}} = useStores();const { essentialGroup } = cookieStore;const presetModel = cookie?.presetModel || cookieStore.presetsCookie.get(preset?.identifier);const groups = cookieStore.groups.sortedGroups.map(({ data: { id, name } }) => ({ id, name }));const allowContentBlockerCreation = !!navigateAfterCreation;const contentBlockerTemplates = presetModel?.data.contentBlockerTemplates || [];const attributes = { ...presetModel?.attributes, ...overwriteAttributes };const { form, isBusy, defaultValues, onFinish, onFinishFailed, onBeforeUnload, onValuesChange, contextValue } =useFormServiceHandler({__,_i,attributes,selectedGroup: group.key,trackFieldsDifferFromDefaultValues: ["group"],setCookiesViaManager,groups,preset: presetModel? {identifier: presetModel.data.identifier,version: presetModel.data.version}: undefined,allowContentBlockerCreation,shouldUncheckContentBlockerCheckbox: attributes?.shouldUncheckContentBlockerCheckbox,contentBlockerTemplates,handleSave: async (values) => {try {// Pass as base64-encoded string to avoid Cloudflare XSS issuesconst codeToBase64 = (str: string) =>useEncodedStringForScriptInputs ? `encodedScript:${base64EncodeUnicodeSafe(str)}` : str;const {name,status,purpose,isEmbeddingOnlyExternalResources,technicalDefinitions,group,codeDynamics,createContentBlocker,createContentBlockerId,consentForwardingUniqueName,codeOptIn,codeOptOut,codeOnPageLoad,...meta} = values;const newMeta = {...meta,codeOptIn: codeToBase64(codeOptIn),codeOptOut: codeToBase64(codeOptOut),codeOnPageLoad: codeToBase64(codeOnPageLoad),isEmbeddingOnlyExternalResources,codeDynamics: JSON.stringify(codeDynamics),// Still hold the data of `technicalDefinitions` in database so it is not cleared when activating this optiontechnicalDefinitions: JSON.stringify(isEmbeddingOnlyExternalResources ? initialValues.technicalDefinitions : technicalDefinitions),consentForwardingUniqueName: consentForwardingUniqueName || slugify(name),presetId: presetModel?.data.identifier,presetVersion: presetModel?.data.version};delete newMeta.presetCheck;if (queried) {cookie.setName(name);cookie.setStatus(status);cookie.setPurpose(purpose);cookie.setMeta(newMeta);cookie.setGroup(group);await cookie.patch();} else {const useGroup = cookieStore.groups.entries.get(group);const draft = new CookieModel(useGroup.cookies, {title: {rendered: name},content: {rendered: purpose,protected: false},status,meta: newMeta});await draft.persist();onCreated?.(draft);}// Remove the item from the "Services with empty privacy policy" global noticeconst noticeId = "#rcb-services-with-empty-privacy-policy-notice";document.querySelector(`${noticeId} li[data-id="${id}"]`)?.classList.add("hidden");if (!document.querySelectorAll(`${noticeId} > ul > li:not(.hidden)`).length) {document.querySelector(noticeId)?.remove();}// Navigate back after creationnavigateAfterCreation &&setTimeout(() =>createContentBlocker? // Navigate to content blocker form and forward `navigateAfterCreation` if givenhistory.push(`/blocker/new?force=${createContentBlockerId || preset.identifier}&cookieCreationPrompt=1${typeof navigateAfterCreation === "string"? `&navigateAfterCreation=${encodeURIComponent(navigateAfterCreation)}`: ""}`): // Navigate back to overview or custom linktypeof navigateAfterCreation === "string"? (window.location.href = navigateAfterCreation): history.push(`${link.slice(1)}/${group}`),0);} catch (e) {throw (e as any).responseJSON.message;}}});const createContentBlockerNotice =attributes?.createContentBlockerNotice || presetModel?.attributes?.createContentBlockerNotice;const initialValues: FormServiceValueProps = fetched? {name: cookie.data.title.raw,status: cookie.data.status as FormServiceValueProps["status"],group: group.key || undefined, // Can be `0`, so fallback to no selection (e.g. Cookie form modal in Content Blocker)purpose: cookie.data.content.raw,provider: cookie.data.meta.provider,providerPrivacyPolicyUrl: cookie.data.meta.providerPrivacyPolicyUrl,consentForwardingUniqueName: cookie.data.meta.consentForwardingUniqueName || cookie.data.slug,isEmbeddingOnlyExternalResources: cookie.data.meta.isEmbeddingOnlyExternalResources,legalBasis: cookie.data.meta.legalBasis,ePrivacyUSA: cookie.data.meta.ePrivacyUSA,technicalDefinitions: JSON.parse(JSON.stringify(cookie.technicalDefinitions || "[]")) as VisualServiceTechnicalDefinition[],codeDynamics: JSON.parse(JSON.stringify(cookie.codeDynamics || "{}")) as Record<string, string>,tagManagerOptInEventName: cookie.data.meta.tagManagerOptInEventName,tagManagerOptOutEventName: cookie.data.meta.tagManagerOptOutEventName,codeOptIn: cookie.data.meta.codeOptIn,executeCodeOptInWhenNoTagManagerConsentIsGiven:cookie.data.meta.executeCodeOptInWhenNoTagManagerConsentIsGiven,codeOptOut: cookie.data.meta.codeOptOut,executeCodeOptOutWhenNoTagManagerConsentIsGiven:cookie.data.meta.executeCodeOptOutWhenNoTagManagerConsentIsGiven,codeOnPageLoad: cookie.data.meta.codeOnPageLoad,deleteTechnicalDefinitionsAfterOptOut: cookie.data.meta.deleteTechnicalDefinitionsAfterOptOut,createContentBlocker: false,createContentBlockerId: undefined,presetCheck: undefined}: defaultValues;// Initially load the cookie if not yet doneuseEffect(() => {if (queried && !fetched) {// Fetch the cookie within the correct group collection so it gets removed// from the original cookie group when it got moved to another cookie group.const groupToFetch =[...cookieStore.groups.entries.values()].filter(({ cookies }) => cookies.entries.get(id))[0] || group;groupToFetch.cookies.getSingle({params: {id,context: "edit"}});}}, [queried, fetched]);// Lazy load attributes of preset modeluseEffect(() => {if (presetModel && !presetModel.attributes) {presetModel.fetchAttributes();}}, [presetModel]);useEffect(() => {if (presetModel && !presetModel.attributes && !presetModel.busy) {presetModel.fetchAttributes();}}, [presetModel]);// Scroll to top when opening the formuseEffect(() => {if (scrollToTop) {scrollTo(0);}}, []);const hasServiceByConsentForwardingUniqueName = useCallback(async (slug: string) => {try {return (((await request<RequestRouteForwardCookieGet,ParamsRouteForwardCookieGet,ResponseRouteForwardCookieGet>({location: locationRestForwardCookieGet,params: {slug}})) as ResponseRouteForwardCookieGet).filter((d) => d.ID !== cookie.key).length > 0);} catch (e) {return false;}},[cookie.key]);const FormServiceContext = FormServiceContextFactory.Context();if ((queried && !fetched) || (presetModel && !presetModel.attributes)) {return <Skeleton active paragraph={{ rows: 8 }} />;}const isTemplateUpdate =fetched && presetModel ? cookie.data?.meta?.presetVersion !== presetModel.data.version : false;return (<FormServiceContext.Providervalue={{...contextValue,isEdit: fetched,isPro,isTemplateUpdate,isTcf: tcf,isDataProcessingInUnsafeCountries: ePrivacyUSA,isConsentForwarding: consentForwarding,hasServiceByConsentForwardingUniqueName,presetCheck: presetModel ? isTemplateUpdate || !fetched : false,serviceGotScanned: !!(presetModel?.data.scanned &&presetModel.attributes?.codeOptIn &&["wordpress-comments"].indexOf(presetModel.data.identifier) === -1),hasManager: hasManager > 0,dynamicFields: attributes?.dynamicFields || presetModel?.attributes?.dynamicFields,essentialGroupId: essentialGroup.key,skipIfActiveComponents: activePlugins,// eslint-disable-next-line react/display-namerenderCodeMirror: () => <CodeMirror settings={(window as any).cm_settings} />,notices: {group: [...contextValue.notices.group,{message: attributes?.groupNotice || presetModel?.attributes?.groupNotice,severity: "info"}],providerPrivacyPolicyUrl: [{message:!fetched && presetModel?.attributes && !initialValues.providerPrivacyPolicyUrl? __('You have not yet set a privacy policy in the settings, so this field could not be filled in automatically. Please enter the URL of your privacy policy here and <a href="%s" target="_blank">set the corresponding page in your settings.</a>',"#/settings"): undefined,severity: "warning"}],createContentBlocker: [{ message: createContentBlockerNotice, severity: "info" }],technicalHandling: [{message:attributes?.technicalHandlingNotice || presetModel?.attributes?.technicalHandlingNotice,severity: "info"}]}}}><Spin spinning={isBusy || presetModel?.busy || false}><Prompt message={onBeforeUnload} /><Formname={`cookie-${group.key}-${id}`}form={form}{...FormServiceLayout}initialValues={initialValues}onFinish={onFinish}onFinishFailed={onFinishFailed}onValuesChange={onValuesChange}><FormService /></Form></Spin></FormServiceContext.Provider>);})

Generated using TypeDoc