Skip to content

Commit

Permalink
Fix termsOfUse acceptance before getting the token
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleguido committed Oct 28, 2024
1 parent 6855dae commit ec53c97
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
6 changes: 6 additions & 0 deletions src/components/TermsOfUseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ const TermsOfUseModal: React.FC<{
[wsStatus, token],
)

useEffect(() => {
// if this is just a login, just close it.
if (acceptedTermsDate && view === BrowserViewTermsOfUse) {
setView(null)
}
}, [acceptedTermsDate])
useEffect(() => {
if (!enableAcceptTermsButton && isIntersecting) {
setEnableAcceptTermsButton(true)
Expand Down
67 changes: 40 additions & 27 deletions src/components/TokenWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,14 @@ const TokenWrapper: React.FC<{ delay?: number }> = ({ delay = 2000 }) => {
<Container>
<h1>
{status === "idle" && !isBusy && "Generate your API token"}
{isBusy && "Generating your API token..."}
{status === "pending" && " Almost there..."}
{(isBusy || status === "pending") && "Generating your API token..."}
{status === "error" &&
errorIsFailure &&
!isBusy &&
"An unexpected error happened. It happens..."}
{status === "success" && !isBusy && "Your Api token"}
</h1>

{showLoginForm && (
<section className="my-4 d-flex flex-column justify-content-center">
<h2 className="mx-auto ">Please login to get your Api Token</h2>
<button
type="submit"
className="btn btn-primary mx-auto d-flex justify-content-center px-5"
onClick={() => setView(BrowserViewLogin)}
>
Log in or Register
</button>
</section>
)}

{errorIsFailure && (
<Alert
type="error"
Expand All @@ -110,28 +96,55 @@ const TokenWrapper: React.FC<{ delay?: number }> = ({ delay = 2000 }) => {
value=""
>
<div className="ms-3">
API access is always subject to the&nbsp;
<button
className="btn btn-link d-inline-block"
onClick={() => {
setView(BrowserViewTermsOfUse)
}}
>
Terms of use
</button>
.{" "}
{acceptTermsDate !== null && (
{acceptTermsDate !== null ? (
<p className="m-0">
You accepted the Terms of Use{" "}
API access is always subject to the&nbsp;
<button
className="btn btn-link d-inline-block"
onClick={() => {
setView(BrowserViewTermsOfUse)
}}
>
Terms of use
</button>
. You accepted the Terms of Use{" "}
<b>
{DateTime.fromISO(acceptTermsDate)
.setLocale("en-GB")
.toLocaleString(DateTime.DATETIME_FULL)}
</b>
</p>
) : (
<p className="m-0">
You have not accepted our <b>Terms of Use</b> yet. Please read the{" "}
<b>entire</b> terms of use document carefully and accept it before
using the token.
</p>
)}
</div>
</Alert>
{acceptTermsDate === null && (
<button
className="btn btn-secondary mt-3 mx-auto"
onClick={() => {
setView(BrowserViewTermsOfUse)
}}
>
Read and accept the Terms of use to generate the token
</button>
)}
{showLoginForm && (
<section className="my-4 d-flex flex-column justify-content-center">
<h2 className="mx-auto ">Please login to get your Api Token</h2>
<button
type="submit"
className="btn btn-secondary mx-auto d-flex justify-content-center px-5"
onClick={() => setView(BrowserViewLogin)}
>
Log in or Register
</button>
</section>
)}
{isBusy && (
<div className="spinner-border text-dark" role="status">
<span className="visually-hidden">Loading...</span>
Expand Down

0 comments on commit ec53c97

Please sign in to comment.