// Dependencies import { linkClasses, validateEmail } from '@freesewing/utils' // Context import { LoadingStatusContext } from '@freesewing/react/context/LoadingStatus' // Hooks import React, { useState, useContext } from 'react' import { useAccount } from '@freesewing/react/hooks/useAccount' import { useBackend } from '@freesewing/react/hooks/useBackend' // Components import { Link as WebLink } from '@freesewing/react/components/Link' import { NoIcon, OkIcon, SaveIcon, RightIcon, WarningIcon } from '@freesewing/react/components/Icon' import { EmailInput } from '@freesewing/react/components/Input' import { Popout } from '@freesewing/react/components/Popout' import { IconButton } from '@freesewing/react/components/Button' /* * Component for newsletter signup (by visitors) * * @params {object} props - All React props * @param {function} props.Link - An optional framework-specific Link component */ export const NewsletterSignup = ({ Link = false, noP = false, noTitle = false, noBox = false }) => { if (!Link) Link = WebLink // Hooks const { account, setAccount } = useAccount() const backend = useBackend() const { setLoadingStatus } = useContext(LoadingStatusContext) // State const [email, setEmail] = useState('') const [unsubscribe, setUnsubscribe] = useState(false) const [subscribed, setSubscribed] = useState(false) // Helper method to handle subscription const subscribe = async () => { setLoadingStatus([true, 'Contacting backend']) const [status, body] = unsubscribe ? await backend.newsletterStartUnsubscribe(email) : await backend.newsletterSubscribe(email) if (status === 200) { setLoadingStatus([true, 'Request Initiated', true, true]) setSubscribed(true) } else setLoadingStatus([true, 'An error occured. Please report this.', true, true]) } return (
We have sent and email to {email} with a link to confirm this action.
Subscribe to our newsletter and once every 3 months you will receive an email from us with honest wholesome content. No tracking, no ads, no nonsense.
)}