B2B-87: add company statistics consent (#29)
* B2B-87: add company statistics consent * add toggle for company statistics consent under profile * add toggle for company statistics consent under profile * add audit logging to accounts * change policy * add audit logging to accounts * remove full account data query and just query the entire account every time * add comment about consent toggle * make constants hardcoded, as dynamic ones do not work * add back pending check --------- Co-authored-by: Helena <helena@Helenas-MacBook-Pro.local>
This commit is contained in:
@@ -16,6 +16,7 @@ import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { usePersonalAccountData } from '../../hooks/use-personal-account-data';
|
||||
import { AccountDangerZone } from './account-danger-zone';
|
||||
import ConsentToggle from './consent/consent-toggle';
|
||||
import { UpdateEmailFormContainer } from './email/update-email-form-container';
|
||||
import { MultiFactorAuthFactorsList } from './mfa/multi-factor-auth-list';
|
||||
import { UpdatePasswordFormContainer } from './password/update-password-container';
|
||||
@@ -150,6 +151,32 @@ export function PersonalAccountSettingsContainer(
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<div className="flex justify-between">
|
||||
<div>
|
||||
<p className="font-medium">
|
||||
<Trans
|
||||
i18nKey={'account:consentToAnonymizedCompanyData.label'}
|
||||
/>
|
||||
</p>
|
||||
|
||||
<CardDescription>
|
||||
<Trans
|
||||
i18nKey={'account:consentToAnonymizedCompanyData.description'}
|
||||
/>
|
||||
</CardDescription>
|
||||
</div>
|
||||
<ConsentToggle
|
||||
userId={props.userId}
|
||||
initialState={
|
||||
!!user.data.has_consent_anonymized_company_statistics
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
|
||||
<If condition={props.features.enableAccountDeletion}>
|
||||
<Card className={'border-destructive'}>
|
||||
<CardHeader>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useState } from 'react';
|
||||
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import { Switch } from '@kit/ui/switch';
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
|
||||
import { useRevalidatePersonalAccountDataQuery } from '../../../hooks/use-personal-account-data';
|
||||
import { useUpdateAccountData } from '../../../hooks/use-update-account';
|
||||
|
||||
// This is temporary. When the profile views are ready, all account values included in the form will be updated together on form submit.
|
||||
export default function ConsentToggle({
|
||||
userId,
|
||||
initialState,
|
||||
}: {
|
||||
userId: string;
|
||||
initialState: boolean;
|
||||
}) {
|
||||
const [isConsent, setIsConsent] = useState(initialState);
|
||||
const updateAccountMutation = useUpdateAccountData(userId);
|
||||
const revalidateUserDataQuery = useRevalidatePersonalAccountDataQuery();
|
||||
|
||||
const updateConsent = (consent: boolean) => {
|
||||
const promise = updateAccountMutation
|
||||
.mutateAsync({
|
||||
has_consent_anonymized_company_statistics: consent,
|
||||
})
|
||||
.then(() => {
|
||||
revalidateUserDataQuery(userId);
|
||||
});
|
||||
|
||||
return toast.promise(() => promise, {
|
||||
success: <Trans i18nKey={'account:updateConsentSuccess'} />,
|
||||
error: <Trans i18nKey={'account:updateConsentError'} />,
|
||||
loading: <Trans i18nKey={'account:updateConsentLoading'} />,
|
||||
});
|
||||
};
|
||||
return (
|
||||
<Switch
|
||||
checked={isConsent}
|
||||
onCheckedChange={setIsConsent}
|
||||
onClick={() => updateConsent(!isConsent)}
|
||||
disabled={updateAccountMutation.isPending}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -22,14 +22,7 @@ export function usePersonalAccountData(
|
||||
|
||||
const response = await client
|
||||
.from('accounts')
|
||||
.select(
|
||||
`
|
||||
id,
|
||||
name,
|
||||
picture_url,
|
||||
last_name
|
||||
`,
|
||||
)
|
||||
.select()
|
||||
.eq('primary_owner_user_id', userId)
|
||||
.eq('is_personal_account', true)
|
||||
.single();
|
||||
|
||||
Reference in New Issue
Block a user