fleet/frontend/pages/MDMAppleSSOCallbackPage/MDMAppleSSOCallbackPage.tsx
Roberto Dip 8e532a5e76
pre-populate username/fullname during account creation (#11557)
Related to #10744, this pre-populates and disables the username/fullname
fields.

https://user-images.githubusercontent.com/4419992/236854781-ac67ee28-c19c-4130-a5e6-2872220501b5.mov


# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Documented any API changes (docs/Using-Fleet/REST-API.md or
docs/Contributing/API-for-contributors.md)
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2023-05-18 12:50:00 -03:00

90 lines
1.9 KiB
TypeScript

import React, { useState } from "react";
import { WithRouterProps } from "react-router";
import endpoints from "utilities/endpoints";
import Spinner from "components/Spinner/Spinner";
import SSOError from "components/MDM/SSOError";
import Button from "components/buttons/Button";
const baseClass = "mdm-apple-sso-callback-page";
const RedirectTo = ({ url }: { url: string }) => {
window.location.href = url;
return <Spinner />;
};
interface IEnrollmentGateProps {
profileToken?: string;
eulaToken?: string;
enrollmentReference?: string;
}
const EnrollmentGate = ({
profileToken,
eulaToken,
enrollmentReference,
}: IEnrollmentGateProps) => {
const [showEULA, setShowEULA] = useState(Boolean(eulaToken));
if (!profileToken) {
return <SSOError />;
}
if (showEULA && eulaToken) {
return (
<div className={`${baseClass}__eula-wrapper`}>
<h3>Terms and conditions</h3>
<iframe
src={`/api/${endpoints.MDM_EULA(eulaToken)}`}
width="100%"
title="eula"
/>
<Button
onClick={() => setShowEULA(false)}
variant="oversized"
className={`${baseClass}__agree-btn`}
>
Agree and continue
</Button>
</div>
);
}
return (
<RedirectTo
url={endpoints.MDM_APPLE_ENROLLMENT_PROFILE(
profileToken,
enrollmentReference
)}
/>
);
};
interface IMDMSSOCallbackQuery {
eula_token?: string;
profile_token?: string;
enrollment_reference?: string;
}
const MDMAppleSSOCallbackPage = (
props: WithRouterProps<object, IMDMSSOCallbackQuery>
) => {
const {
eula_token,
profile_token,
enrollment_reference,
} = props.location.query;
return (
<div className={baseClass}>
<EnrollmentGate
eulaToken={eula_token}
profileToken={profile_token}
enrollmentReference={enrollment_reference}
/>
</div>
);
};
export default MDMAppleSSOCallbackPage;