|
| 1 | +import React from "react"; |
| 2 | +import { useTranslation } from "next-i18next"; |
| 3 | +import styled from "styled-components"; |
| 4 | +import IconButton from "./IconButton"; |
| 5 | +import { IconArrowRight } from "hds-react"; |
| 6 | +import { fontBold, H1 } from "../common/typography"; |
| 7 | +import { breakpoints } from "../common/style"; |
| 8 | +import Image from "next/image"; |
| 9 | + |
| 10 | +const IMAGE_WIDTH = "418"; |
| 11 | +const IMAGE_HEIGHT = "350"; |
| 12 | + |
| 13 | +const ErrorContainer = styled.div` |
| 14 | + display: flex; |
| 15 | + flex-direction: column; |
| 16 | + gap: var(--spacing-xl); |
| 17 | + padding-top: var(--spacing-xl); |
| 18 | + @media (min-width: ${breakpoints.m}) { |
| 19 | + flex-direction: row; |
| 20 | + } |
| 21 | +`; |
| 22 | + |
| 23 | +const Img = styled(Image)` |
| 24 | + object-fit: contain; |
| 25 | + width: auto; |
| 26 | + height: auto; |
| 27 | + margin: 0 auto; |
| 28 | + @media (min-width: ${breakpoints.l}) { |
| 29 | + flex-grow: 1; |
| 30 | + display: flex; |
| 31 | + max-width: ${`${IMAGE_WIDTH}px`}; |
| 32 | + } |
| 33 | +`; |
| 34 | + |
| 35 | +const TextContent = styled.div` |
| 36 | + display: flex; |
| 37 | + flex-direction: column; |
| 38 | + gap: var(--spacing-xl); |
| 39 | + justify-content: center; |
| 40 | + @media (min-width: ${breakpoints.m}) { |
| 41 | + order: -1; |
| 42 | + } |
| 43 | +`; |
| 44 | + |
| 45 | +const Body = styled.p` |
| 46 | + margin: 0; |
| 47 | +`; |
| 48 | + |
| 49 | +const Email = styled.a` |
| 50 | + ${fontBold} |
| 51 | +`; |
| 52 | + |
| 53 | +const constructFeedbackUrl = ( |
| 54 | + feedbackUrl: string, |
| 55 | + i18n: { language: string } |
| 56 | +) => { |
| 57 | + try { |
| 58 | + const url = new URL(feedbackUrl); |
| 59 | + url.searchParams.set("lang", i18n.language); |
| 60 | + return url.toString(); |
| 61 | + } catch (e) { |
| 62 | + return null; |
| 63 | + } |
| 64 | +}; |
| 65 | + |
| 66 | +const DeactivatedAccount = ({ |
| 67 | + feedbackUrl, |
| 68 | + imgSrc, |
| 69 | +}: { |
| 70 | + feedbackUrl: string; |
| 71 | + imgSrc: string; |
| 72 | +}) => { |
| 73 | + const { t, i18n } = useTranslation(); |
| 74 | + return ( |
| 75 | + <ErrorContainer> |
| 76 | + <Img |
| 77 | + src={imgSrc} |
| 78 | + alt={t("errors:deactivatedAccount.heading")} |
| 79 | + width={IMAGE_WIDTH} |
| 80 | + height={IMAGE_HEIGHT} |
| 81 | + aria-hidden="true" |
| 82 | + /> |
| 83 | + <TextContent> |
| 84 | + <H1>{t("errors:deactivatedAccount.heading")}</H1> |
| 85 | + <Body> |
| 86 | + {`${t("errors:deactivatedAccount.subHeadingA")} `} |
| 87 | + <Email href={`mailto:${t("errors:deactivatedAccount.email")}`}> |
| 88 | + {t("errors:deactivatedAccount.email")} |
| 89 | + </Email> |
| 90 | + {` ${t("errors:deactivatedAccount.subHeadingB")}`} |
| 91 | + </Body> |
| 92 | + <IconButton |
| 93 | + label={t("errors:deactivatedAccount.button")} |
| 94 | + icon={<IconArrowRight aria-hidden="true" />} |
| 95 | + href={constructFeedbackUrl(feedbackUrl, i18n) ?? feedbackUrl} |
| 96 | + rel="noopener noreferrer" |
| 97 | + /> |
| 98 | + </TextContent> |
| 99 | + </ErrorContainer> |
| 100 | + ); |
| 101 | +}; |
| 102 | + |
| 103 | +export default DeactivatedAccount; |
0 commit comments