Skip to content

Commit

Permalink
allow clickaway to escape consent options in UserSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
andracc committed Dec 18, 2024
1 parent 9a91fc8 commit 20558e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
23 changes: 11 additions & 12 deletions src/components/AnalyticsConsent/AnalyticsConsent.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import { Button } from "@mui/material";
import Drawer from "@mui/material/Drawer";
import { ReactElement, useState } from "react";
import { ReactElement } from "react";

interface ConsentProps {
onChangeConsent: (consentVal: boolean) => void;
onChangeConsent: (consentVal: boolean | undefined) => void;
required: boolean;
}

export function AnalyticsConsent(props: ConsentProps): ReactElement {

const [responded, setResponded] = useState(false);
const acceptAnalytics = (): void => {

setResponded(true);
props.onChangeConsent(true);
};
const rejectAnalytics = (): void => {

setResponded(false);
props.onChangeConsent(false);
};

const clickedAway = (): void => {
props.onChangeConsent(undefined);
};

return (
<div>
<Drawer anchor={"bottom"} open={!responded}>
MyDrawer!
<Drawer
anchor={"bottom"}
open
onClose={!props.required ? clickedAway : undefined}
>
<button onClick={acceptAnalytics}>Accept</button>
<button onClick={rejectAnalytics}>Reject</button>
</Drawer>

</div>
);
}
5 changes: 4 additions & 1 deletion src/components/App/AppLoggedIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export default function AppWithBar(): ReactElement {
getCurrentUser()?.answeredConsent
);

async function handleConsentChange(otelConsent: boolean): Promise<void> {
async function handleConsentChange(
otelConsent: boolean | undefined
): Promise<void> {
await updateUser({
...getCurrentUser()!,
otelConsent,
Expand Down Expand Up @@ -101,6 +103,7 @@ export default function AppWithBar(): ReactElement {
{answeredConsent ? null : (
<AnalyticsConsent
onChangeConsent={handleConsentChange}
required
></AnalyticsConsent>
)}
<Routes>
Expand Down
5 changes: 3 additions & 2 deletions src/components/UserSettings/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export function UserSettings(props: {
const [displayConsent, setDisplayConsent] = useState(false);
const show = (): void => setDisplayConsent(true);

const handleConsentChange = (consentVal: boolean): void => {
setOtelConsent(consentVal);
const handleConsentChange = (consentVal: boolean | undefined): void => {
setOtelConsent(consentVal ?? otelConsent);
setDisplayConsent(false);
};

Expand Down Expand Up @@ -308,6 +308,7 @@ export function UserSettings(props: {
{displayConsent ? (
<AnalyticsConsent
onChangeConsent={handleConsentChange}
required={false}
></AnalyticsConsent>
) : null}
</Grid>
Expand Down

0 comments on commit 20558e9

Please sign in to comment.