mirror of
https://github.com/fleetdm/fleet
synced 2026-05-20 15:38:39 +00:00
# Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Sarah Gillespie <73313222+gillespi314@users.noreply.github.com>
95 lines
2.4 KiB
TypeScript
95 lines
2.4 KiB
TypeScript
import React, { useContext } from "react";
|
|
import { InjectedRouter } from "react-router";
|
|
import { useQuery } from "react-query";
|
|
import { AxiosError } from "axios";
|
|
|
|
import mdmAppleAPI, {
|
|
IGetVppTokensResponse,
|
|
} from "services/entities/mdm_apple";
|
|
import { DEFAULT_USE_QUERY_OPTIONS } from "utilities/constants";
|
|
import { AppContext } from "context/app";
|
|
|
|
import DataError from "components/DataError";
|
|
import Spinner from "components/Spinner";
|
|
import PremiumFeatureMessage from "components/PremiumFeatureMessage";
|
|
|
|
import AddSoftwareVppForm from "./AddSoftwareVppForm";
|
|
import { teamHasVPPToken } from "./helpers";
|
|
|
|
const baseClass = "software-app-store-vpp";
|
|
//
|
|
interface ISoftwareAppStoreProps {
|
|
currentTeamId: number;
|
|
router: InjectedRouter;
|
|
}
|
|
|
|
const SoftwareAppStoreVpp = ({
|
|
currentTeamId,
|
|
router,
|
|
}: ISoftwareAppStoreProps) => {
|
|
const { isPremiumTier } = useContext(AppContext);
|
|
|
|
const {
|
|
data: vppInfo,
|
|
isLoading: isLoadingVppInfo,
|
|
error: errorVppInfo,
|
|
} = useQuery<IGetVppTokensResponse, AxiosError>(
|
|
["vppInfo", currentTeamId],
|
|
() => mdmAppleAPI.getVppTokens(),
|
|
{
|
|
...DEFAULT_USE_QUERY_OPTIONS,
|
|
staleTime: 30000,
|
|
retry: (tries, error) => error.status !== 404 && tries <= 3,
|
|
}
|
|
);
|
|
|
|
const noVppTokenUploaded = !vppInfo || !vppInfo.vpp_tokens.length;
|
|
const hasVppToken = teamHasVPPToken(currentTeamId, vppInfo?.vpp_tokens);
|
|
|
|
const {
|
|
data: vppApps,
|
|
isLoading: isLoadingVppApps,
|
|
error: errorVppApps,
|
|
} = useQuery(
|
|
["vppSoftware", currentTeamId],
|
|
() => mdmAppleAPI.getVppApps(currentTeamId),
|
|
{
|
|
...DEFAULT_USE_QUERY_OPTIONS,
|
|
enabled: hasVppToken,
|
|
staleTime: 30000,
|
|
select: (res) => res.app_store_apps,
|
|
}
|
|
);
|
|
|
|
const renderContent = () => {
|
|
if (!isPremiumTier) {
|
|
return (
|
|
<PremiumFeatureMessage className={`${baseClass}__premium-message`} />
|
|
);
|
|
}
|
|
|
|
if (isLoadingVppInfo || isLoadingVppApps) {
|
|
return <Spinner />;
|
|
}
|
|
|
|
if (errorVppInfo || errorVppApps) {
|
|
return <DataError className={`${baseClass}__error`} />;
|
|
}
|
|
|
|
return (
|
|
<div className={`${baseClass}__content`}>
|
|
<AddSoftwareVppForm
|
|
router={router}
|
|
teamId={currentTeamId}
|
|
hasVppToken={hasVppToken}
|
|
noVppTokenUploaded={noVppTokenUploaded}
|
|
vppApps={vppApps}
|
|
/>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
return <div className={baseClass}>{renderContent()}</div>;
|
|
};
|
|
|
|
export default SoftwareAppStoreVpp;
|