-
Notifications
You must be signed in to change notification settings - Fork 34
Optional terms of use dialog for user #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
schuettloeffel-elsa
wants to merge
15
commits into
opencast:develop
Choose a base branch
from
schuettloeffel-elsa:296-terms-of-use
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
73596e2
initial terms of use
schuettloeffel-elsa 7a6a15d
next
schuettloeffel-elsa cb568cf
Merge remote-tracking branch 'origin/main' into 296-terms-of-use
schuettloeffel-elsa 4ea9ccf
next
schuettloeffel-elsa 4a8c71d
added .vscode to gitignore
schuettloeffel-elsa 2005f13
remove warnings
schuettloeffel-elsa 20a2a76
fix some more issues
schuettloeffel-elsa f6fae19
removed .vscode from gitignore
schuettloeffel-elsa 6f20599
removed padding at bottom from overlay
schuettloeffel-elsa acaab2c
fixed various issues in TermsOfUseModal.tsx, added translation for su…
schuettloeffel-elsa dd13fa7
fixed some more issues with src/components/shared/TermsOfUseModal.tsx
schuettloeffel-elsa 3f0ec7d
some small changes
schuettloeffel-elsa 55dad2f
change string to english
schuettloeffel-elsa 5420b55
make sure true or false is commitet to backend
schuettloeffel-elsa 9ba71c8
bugfix last commit
schuettloeffel-elsa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,152 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Field, Formik } from "formik"; | ||
import cn from "classnames"; | ||
import axios from "axios"; | ||
import i18n from "../../i18n/i18n"; | ||
import DOMPurify from "dompurify"; | ||
|
||
// Generate URL for terms based on the languae | ||
const getURL = (language: string) => { | ||
return `/ui/config/admin-ui/terms.${language}.html`; | ||
}; | ||
|
||
const TermsOfUseModal = () => { | ||
const { t } = useTranslation(); | ||
const [termsContent, setTermsContent] = useState(""); | ||
const [agreedToTerms, setAgreedToTerms] = useState(true); | ||
|
||
// Check if already accepted terms | ||
useEffect(() => { | ||
const checkTerms = async () => { | ||
schuettloeffel-elsa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
const response = await axios.get("/admin-ng/user-settings/settings.json"); | ||
// @ts-expect-error TS(7006): Parameter 'result' implicitly has an 'any' type. | ||
const isAgreed = response.data.results.find(result => result.key === "agreedToTerms").value === "true"; | ||
setAgreedToTerms(isAgreed); | ||
} catch (error) { | ||
console.error("Error while retrieving data: ", error); | ||
setAgreedToTerms(false); | ||
} | ||
}; | ||
|
||
checkTerms(); | ||
schuettloeffel-elsa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, []); | ||
|
||
// Fetch terms | ||
useEffect(() => { | ||
axios.get(getURL(i18n.language)) | ||
schuettloeffel-elsa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.then(response => { | ||
setTermsContent(response.data); | ||
}) | ||
.catch(error => { | ||
axios.get(getURL(typeof i18n.options.fallbackLng === 'string' ? i18n.options.fallbackLng : 'en-US')) | ||
schuettloeffel-elsa marked this conversation as resolved.
Show resolved
Hide resolved
gregorydlogan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.then(response => { | ||
setTermsContent(response.data); | ||
}) | ||
.catch(error => { | ||
console.error('Error while fetching data:', error); | ||
setTermsContent(t("TERMS.NOCONTENT")); | ||
}); | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [agreedToTerms]); // Listen to changes in agreedToTerms | ||
|
||
// Set terms to user settings | ||
// @ts-expect-error TS(7006): Parameter 'values' implicitly has an 'any' type. | ||
const handleSubmit = async (values) => { | ||
let body = new URLSearchParams(); | ||
body.append("key", "agreedToTerms"); | ||
body.append("value", values.agreedToTerms ? "true" : "false"); | ||
|
||
await axios.post("/admin-ng/user-settings/setting", body, { | ||
schuettloeffel-elsa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
}); | ||
setAgreedToTerms(true); | ||
}; | ||
|
||
// If already accepted terms, dont display anything | ||
if (agreedToTerms) { | ||
schuettloeffel-elsa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return null; | ||
} | ||
|
||
// Else display terms | ||
return ( | ||
<> | ||
<div className="modal-animation modal-overlay" /> | ||
<section id="registration-modal" className="modal active modal-open modal-animation"> | ||
<header> | ||
<h2>{t("TERMS.TITLE")}</h2> | ||
</header> | ||
|
||
<div className="modal-content" style={{ display: "block" }}> | ||
<div className="modal-body"> | ||
<div> | ||
<div className="row"> | ||
<div className="scrollbox"> | ||
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(termsContent) }} ></div> | ||
schuettloeffel-elsa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<Formik | ||
initialValues={{}} | ||
enableReinitialize | ||
onSubmit={handleSubmit} | ||
> | ||
{(formik) => (<> | ||
<div className="modal-content" style={{ display: "block" }}> | ||
<div className="modal-body"> | ||
<div> | ||
<fieldset> | ||
<legend>{t("TERMS.TITLE")}</legend> | ||
<div className="form-group form-group-checkbox"> | ||
<Field | ||
type="checkbox" | ||
name="agreedToTerms" | ||
id="agreedToTerms" | ||
className="form-control" | ||
/> | ||
<label htmlFor="agreedToTerms"> | ||
<span>{t("TERMS.AGREE")}</span> | ||
</label> | ||
</div> | ||
</fieldset> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<footer> | ||
<div className="pull-right"> | ||
<button | ||
disabled={ | ||
// @ts-expect-error TS(2339): Property 'agreedToTerms' does not exist on type '... Remove this comment to see the full error message | ||
!(formik.isValid && formik.values.agreedToTerms) | ||
} | ||
onClick={() => formik.handleSubmit()} | ||
className={cn("submit", { | ||
active: | ||
// @ts-expect-error TS(2339): Property 'agreedToTerms' does not exist on type '... Remove this comment to see the full error message | ||
formik.isValid && formik.values.agreedToTerms, | ||
inactive: !( | ||
// @ts-expect-error TS(2339): Property 'agreedToTerms' does not exist on type '... Remove this comment to see the full error message | ||
formik.isValid && formik.values.agreedToTerms | ||
), | ||
})} | ||
> | ||
{t("SUBMIT")} | ||
</button> | ||
</div> | ||
</footer> | ||
</>)} | ||
</Formik> | ||
</section> | ||
</> | ||
); | ||
}; | ||
|
||
export default TermsOfUseModal; |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.