11import React , { useEffect , useMemo , useState } from "react" ;
2- import styled , { css , useTheme } from "styled-components" ;
2+ import styled , { css } from "styled-components" ;
33
44import { useNavigate , useSearchParams } from "react-router-dom" ;
55import { isAddress } from "viem" ;
@@ -57,6 +57,7 @@ const textCss = css`
5757
5858const Header = styled . h1 < { fontColor : string } > `
5959 ${ textCss }
60+ white-space: pre-line;
6061 ${ ( { fontColor } ) =>
6162 css `
6263 color: ${ fontColor } ;
@@ -90,8 +91,44 @@ const IconContainer = styled.div`
9091 }
9192` ;
9293
94+ const messageConfigs = {
95+ invalid : {
96+ headerMsg : "Invalid Link!" ,
97+ subtitleMsg : "Oops, seems like you followed an invalid link." ,
98+ buttonMsg : "Contact Support" ,
99+ buttonTo : "/" ,
100+ Icon : InvalidIcon ,
101+ color : "primaryText" ,
102+ } ,
103+ error : {
104+ headerMsg : "Something went wrong" ,
105+ subtitleMsg : "Oops, seems like something went wrong in our systems" ,
106+ buttonMsg : "Contact Support" ,
107+ buttonTo : "/" ,
108+ Icon : WarningIcon ,
109+ color : "error" ,
110+ } ,
111+ confirmed : {
112+ headerMsg : "Congratulations! \nYour email has been verified!" ,
113+ subtitleMsg :
114+ "We'll remind you when your actions are required on Court, and send you notifications on key moments to help you achieve the best of Kleros." ,
115+ buttonMsg : "Let's start!" ,
116+ buttonTo : "/" ,
117+ Icon : CheckIcon ,
118+ color : "success" ,
119+ } ,
120+ expired : {
121+ headerMsg : "Verification link expired..." ,
122+ subtitleMsg :
123+ "Oops, the email verification link has expired. No worries! Go to settings and click on Resend it to receive another verification email." ,
124+ buttonMsg : "Open Settings" ,
125+ buttonTo : "/#notifications" ,
126+ Icon : WarningIcon ,
127+ color : "warning" ,
128+ } ,
129+ } ;
130+
93131const EmailConfirmation : React . FC = ( ) => {
94- const theme = useTheme ( ) ;
95132 const { confirmEmail } = useAtlasProvider ( ) ;
96133
97134 const [ isConfirming , setIsConfirming ] = useState ( false ) ;
@@ -118,44 +155,12 @@ const EmailConfirmation: React.FC = () => {
118155 }
119156 } , [ address , token , confirmEmail ] ) ;
120157
121- const [ headerMsg , subtitleMsg , buttonMsg , buttonTo , Icon , color ] = useMemo ( ( ) => {
122- if ( ! address || ! isAddress ( address ) || ! token || isTokenInvalid )
123- return [
124- "Invalid Link!" ,
125- "Oops, seems like you followed an invalid link." ,
126- "Contact Support" ,
127- "/" ,
128- InvalidIcon ,
129- theme . primaryText ,
130- ] ;
131- else if ( isError )
132- return [
133- "Something went wrong" ,
134- "Oops, seems like something went wrong in our systems" ,
135- "Contact Support" ,
136- "/" ,
137- WarningIcon ,
138- theme . error ,
139- ] ;
140- else if ( isConfirmed )
141- return [
142- "Congratulations! Your email has been verified!" ,
143- "We'll remind you when your actions are required on Court, and send you notifications on key moments to help you achieve the best of Kleros." ,
144- "Let's start!" ,
145- "/" ,
146- CheckIcon ,
147- theme . success ,
148- ] ;
149- else
150- return [
151- "Verification link expired..." ,
152- "Oops, the email verification link has expired. No worries! Go to settings and click on Resend it to receive another verification email." ,
153- "Open Settings" ,
154- "/#notifications" ,
155- WarningIcon ,
156- theme . warning ,
157- ] ;
158- } , [ address , token , isError , isConfirmed , isTokenInvalid , theme ] ) ;
158+ const { headerMsg, subtitleMsg, buttonMsg, buttonTo, Icon, color } = useMemo ( ( ) => {
159+ if ( ! address || ! isAddress ( address ) || ! token || isTokenInvalid ) return messageConfigs . invalid ;
160+ if ( isError ) return messageConfigs . error ;
161+ if ( isConfirmed ) return messageConfigs . confirmed ;
162+ return messageConfigs . expired ;
163+ } , [ address , token , isError , isConfirmed , isTokenInvalid ] ) ;
159164
160165 return (
161166 < Container >
0 commit comments