-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add page to confirm your mail after registering (#68)
- Loading branch information
Showing
3 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"use server" | ||
|
||
export const postMailConfirmationToken = async (token: string): Promise<any> => { | ||
try { | ||
const response = await fetch(`${process.env.CC_API_URL}/accounts/confirm-account`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ token }), | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorResponse = await response.json(); | ||
if (errorResponse.error) { | ||
if (typeof errorResponse.error === 'string') { | ||
return { error: errorResponse.error }; | ||
} else if (errorResponse.error.token) { | ||
return { error: errorResponse.error.token.join(' ') }; | ||
} else if (errorResponse.error.non_field_errors) { | ||
return { error: errorResponse.error.non_field_errors.join(' ') }; | ||
} | ||
} | ||
return { error: "An unexpected error occurred." }; | ||
} | ||
|
||
return { success: true }; | ||
} catch (error) { | ||
return { error: "An unexpected error occurred." }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use client" | ||
import {usePathname} from "next/navigation"; | ||
import {postMailConfirmationToken} from "./actions"; | ||
import React, {useEffect, useState} from "react"; | ||
import Panel from "../../common/uiLibrary/panel"; | ||
import ContactInformation from "../../(home)/contactInformation"; | ||
|
||
const MailConfirmationPage = () => { | ||
const [response, setResponse] = useState<{ success?: boolean; error?: string }>({}); | ||
const token = usePathname().split('/').filter(Boolean).pop(); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
if (token) { | ||
return await postMailConfirmationToken(token); | ||
} | ||
}; | ||
|
||
fetchData().then(r => { | ||
setResponse(r); | ||
}); | ||
}, []); | ||
|
||
if (!token) { | ||
return <main> | ||
</main>; | ||
} | ||
|
||
return ( | ||
<main className="flex flex-col justify-between min-h-screen pt-8 pb-16 lg:pt-16 lg:pb-24"> | ||
<div> | ||
<Panel> | ||
<div | ||
className="mb-4 text-4xl text-center font-extrabold leading-tight lg:mb-6 text-white"> | ||
{response.success ? ( | ||
<h1>Confirmation successful!</h1> | ||
) : ( | ||
<h1>{response.error || 'Waiting for confirmation...'}</h1> | ||
)} | ||
</div> | ||
</Panel> | ||
</div> | ||
<ContactInformation/> | ||
</main> | ||
); | ||
}; | ||
|
||
export default MailConfirmationPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters