Skip to content

Commit

Permalink
Disable login button if user don't want to share data (#49)
Browse files Browse the repository at this point in the history
Signed-off-by: Montse Ortega <[email protected]>
  • Loading branch information
ammont82 authored Dec 2, 2024
1 parent 20b797d commit 41bfc75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apps/agent/src/login-form/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ export const LoginForm: React.FC<LoginForm.Props> = (props) => {
name="isDataSharingAllowed"
label="I agree to share aggregated data about my environment with Red Hat."
aria-label="Share aggregated data"
onChange={(_event,checked)=>vm.handleChangeDataSharingAllowed(checked)}
isChecked={vm.isDataSharingChecked}
/>
</FormGroup>

Expand Down Expand Up @@ -236,7 +238,7 @@ export const LoginForm: React.FC<LoginForm.Props> = (props) => {
<Button
type="submit"
variant="primary"
isDisabled={vm.shouldDisableFormControl}
isDisabled={vm.shouldDisableFormControl || !vm.isDataSharingChecked}
form="login-form"
>
Log in
Expand Down
10 changes: 9 additions & 1 deletion apps/agent/src/login-form/hooks/UseViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface LoginFormViewModelInterface {
shouldDisplayAlert: boolean;
handleSubmit: React.FormEventHandler<HTMLFormElement>;
handleReturnToAssistedMigration: () => void;
handleChangeDataSharingAllowed: (checked:boolean)=>void;
isDataSharingChecked: boolean;
}

const _computeFormControlVariant = (
Expand All @@ -58,14 +60,15 @@ export const useViewModel = (): LoginFormViewModelInterface => {
);
const formRef = useRef<HTMLFormElement>();
const agentApi = useInjection<AgentApiInterface>(Symbols.AgentApi);
const [isDataSharingAllowed,setIsDataSharingAllowed] = useState<boolean>(DATA_SHARING_ALLOWED_DEFAULT_STATE);

useMount(() => {
const form = formRef.current;
if (!form) {
return;
}

form["isDataSharingAllowed"].checked = DATA_SHARING_ALLOWED_DEFAULT_STATE;
form["isDataSharingAllowed"].checked = isDataSharingAllowed;
});

useAsync(async () => {
Expand Down Expand Up @@ -226,5 +229,10 @@ export const useViewModel = (): LoginFormViewModelInterface => {
const assistedMigrationUrl = import.meta.env.ASSISTED_MIGRATION_URL || 'http://localhost:3000/migrate/wizard';
window.open(assistedMigrationUrl, '_blank', 'noopener,noreferrer');
}, []),
handleChangeDataSharingAllowed: useCallback((checked)=>{
console.log(checked);
setIsDataSharingAllowed(checked);
},[]),
isDataSharingChecked: isDataSharingAllowed
};
};

0 comments on commit 41bfc75

Please sign in to comment.