Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPF-477-Add polling to check for key visibility upgrade #1137

Merged
merged 11 commits into from
Jun 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const Credentials = ({
subscription,
type,
keyVisibility,
keyVisibilityUpgrade,
legacyAuthConsumers,
authClients,
oldCredentialsExpirationDate,
Expand All @@ -40,7 +41,9 @@ export const Credentials = ({
const hasAnyCredentials = Boolean(
legacyAuthConsumers.length || authClients.length
);
usePolling(!hasAnyCredentials, { only: ["integration"] });
const isV1Upgraded =
keyVisibility === KeyVisibility.v1 && !!keyVisibilityUpgrade;
usePolling(!hasAnyCredentials || isV1Upgraded, { only: ["integration"] });
const credentials = useMemo(
() => ({
legacyTestConsumer: legacyAuthConsumers.find(
Expand Down Expand Up @@ -96,6 +99,7 @@ export const Credentials = ({
type={type}
subscription={subscription}
keyVisibility={keyVisibility}
keyVisibilityUpgrade={keyVisibilityUpgrade}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import type { Integration } from "../../../types/Integration";
import { KeyVisibility } from "../../../types/KeyVisibility";
import { router } from "@inertiajs/react";
import { Link } from "../../Link";
import { Alert } from "../../Alert";

type Props = Pick<
Integration,
"id" | "status" | "subscription" | "type" | "keyVisibility"
| "id"
| "status"
| "subscription"
| "type"
| "keyVisibility"
| "keyVisibilityUpgrade"
> &
Credentials & { email: string };

Expand All @@ -27,8 +33,10 @@ export const CredentialsAuthClients = ({
subscription,
type,
keyVisibility,
keyVisibilityUpgrade,
}: Props) => {
const { t } = useTranslation();
const isKeyVisibilityV1 = keyVisibility === KeyVisibility.v1;

const auth0TestClientWithLabels = [
{
Expand Down Expand Up @@ -62,27 +70,32 @@ export const CredentialsAuthClients = ({
<Heading className="font-semibold lg:min-w-60" level={4}>
{t("details.credentials.uitid_v2")}
</Heading>
{keyVisibility === KeyVisibility.v1 ? (
<div className="flex flex-col flex-1 gap-4">
<div>
<Trans
i18nKey="details.credentials.uitid_alert"
components={[
<Link
key={t("details.credentials.uitid_alert")}
href={t("details.credentials.uitid_alert_link")}
className="text-publiq-blue-dark hover:underline mb-3"
/>,
]}
/>
{isKeyVisibilityV1 ? (
keyVisibilityUpgrade ? (
<Alert variant="info">{t("integrations.pending_credentials")}</Alert>
) : (
<div className="flex flex-col flex-1 gap-4">
<div>
<Trans
i18nKey="details.credentials.uitid_alert"
components={[
<Link
key={t("details.credentials.uitid_alert")}
href={t("details.credentials.uitid_alert_link")}
className="text-publiq-blue-dark hover:underline mb-3"
/>,
]}
/>
</div>

<ButtonPrimary
className="self-start"
onClick={handleKeyVisibilityUpgrade}
>
{t("details.credentials.action_uitid")}
</ButtonPrimary>
</div>
<ButtonPrimary
className="self-start"
onClick={handleKeyVisibilityUpgrade}
>
{t("details.credentials.action_uitid")}
</ButtonPrimary>
</div>
)
) : (
<div className="flex flex-col flex-1 gap-4">
<div className="flex flex-col gap-3">
Expand Down
6 changes: 6 additions & 0 deletions resources/ts/types/Integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export type Coupon = {
reduction: number;
};

type KeyVisibilityUpgrade = {
id: string;
integrationId: string;
keyVisibility: string;
};
export type Integration = {
id: string;
type: Values<typeof IntegrationType>;
Expand All @@ -32,4 +37,5 @@ export type Integration = {
authClients: AuthClient[];
legacyAuthConsumers: LegacyAuthConsumer[];
keyVisibility: KeyVisibility;
keyVisibilityUpgrade: KeyVisibilityUpgrade | null;
};
Loading