UNPKG

@progress/sitefinity-nextjs-sdk

Version:

Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.

42 lines (41 loc) 2.66 kB
'use client'; import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import React from 'react'; import { serializeForm, SF_WEBSERVICE_API_KEY_HEADER } from '../common/utils'; export function ActivationClient(props) { const { viewProps } = props; const labels = viewProps.labels; const formRef = React.useRef(null); const [sendAgain, setSendAgain] = React.useState(false); const [confirmationContainerHeader, setConfirmationContainerHeader] = React.useState(labels.activationExpiredHeader); const [confirmationContainerLabel, setConfirmationContainerLabel] = React.useState(labels.activationExpiredLabel.replace('{0}', viewProps.email ? viewProps.email : '')); const [confirmationContainerBtnText, setConfirmationContainerBtnText] = React.useState(labels.activationExpiredBtnText); const handleSubmit = (event) => { event.preventDefault(); const form = formRef.current; const url = form.attributes['action'].value; let model = { model: serializeForm(form) }; const headers = {}; if (props.viewProps.webserviceApiKey) { headers[SF_WEBSERVICE_API_KEY_HEADER] = props.viewProps.webserviceApiKey; } window .fetch(url, { method: 'POST', body: JSON.stringify(model), headers }) .then(() => { if (sendAgain) { setConfirmationContainerLabel(labels.sendAgainLabel.replace('{0}', viewProps.email ? viewProps.email : '')); } else { setConfirmationContainerHeader(labels.activationLinkHeader); setConfirmationContainerLabel(`${labels.activationLinkLabel} ${viewProps.email ? viewProps.email : ''}`); setConfirmationContainerBtnText(labels.sendAgainLink); setSendAgain(true); } }); }; return (_jsx(_Fragment, { children: _jsx("div", { "data-sf-role": "confirm-registration-message-container", children: _jsxs("form", { ref: formRef, role: "form", noValidate: true, method: "post", action: props.action, onSubmit: handleSubmit, children: [_jsx("h3", { children: confirmationContainerHeader }), _jsx("p", { "data-sf-role": "activation-link-message-container", children: confirmationContainerLabel }), _jsx("input", { type: "hidden", name: "Email", value: viewProps.email }), _jsx("input", { type: "hidden", name: "ActivationPageUrl", value: viewProps.activationPageUrl }), _jsx("input", { type: "submit", "data-sf-role": "sendAgainLink", className: "btn btn-primary", value: confirmationContainerBtnText })] }) }) })); }