start-plan-followup.fixture.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { useState } from "react";
  2. import { createRoot } from "react-dom/client";
  3. import { getModelProviderFamilySpec } from "@zcode/shared";
  4. import { ZCodeIntlProvider, useZCodeIntl } from "@/i18n/IntlProvider.js";
  5. import { CodingPlanStatusPanel } from "@/settings/model-provider-section/StatusCards.js";
  6. import { ProviderFamilyPlanModeSwitch } from "@/settings/model-provider-section/ProviderFamilyModeHeader.js";
  7. import type {
  8. ModelProviderNavItem,
  9. CodingPlanStatus,
  10. } from "@/settings/model-provider-section/constants.js";
  11. import { TooltipProvider } from "@/components/ui/tooltip.js";
  12. import { formatModelChangeLabel } from "@/v4/composer/modelTriggerDisplay.js";
  13. import "@/styles.css";
  14. const params = new URLSearchParams(location.search);
  15. const family = getModelProviderFamilySpec(params.get("family") === "zai" ? "zai" : "bigmodel");
  16. const state = params.get("state") ?? "disconnected";
  17. const status: CodingPlanStatus =
  18. state === "empty" || state === "pending"
  19. ? "purchased"
  20. : state === "expired"
  21. ? "unavailable"
  22. : (state as CodingPlanStatus);
  23. const common = {
  24. oauthProviderId: family.oauthProviderId,
  25. label: "Team",
  26. providerName: family.id,
  27. provider: null,
  28. status: "purchased" as const,
  29. statusActive: true,
  30. };
  31. const items: ModelProviderNavItem[] = [
  32. {
  33. ...common,
  34. key: "team",
  35. type: "teamPlan",
  36. presetId: family.teamCodingPlanProviderId,
  37. teamPlanName: "InternationalResearchAndDevelopmentOrganization 北京智谱团队",
  38. currentProductId: "p",
  39. organizationId: "o",
  40. projectId: "j",
  41. },
  42. {
  43. ...common,
  44. key: "personal",
  45. type: "codingPlan",
  46. presetId: family.individualCodingPlanProviderId,
  47. },
  48. ];
  49. document.documentElement.className =
  50. params.get("theme") === "light" ? "light theme-zai-light" : "dark theme-zai-dark";
  51. function Fixture() {
  52. const { intl } = useZCodeIntl();
  53. const [selected, setSelected] = useState(items[0]!);
  54. const [actions, setActions] = useState(0);
  55. return (
  56. <main className="min-h-screen bg-background p-4 text-ui-base text-foreground">
  57. <section className="mx-auto max-w-2xl space-y-4" data-testid="panel">
  58. <ProviderFamilyPlanModeSwitch
  59. selectedNavItem={selected}
  60. navigationItems={items}
  61. onSelectNavItem={setSelected}
  62. connectionSelections={{
  63. [family.id]:
  64. selected.key === "team"
  65. ? { kind: "team-coding-plan", productId: "p", organizationId: "o", projectId: "j" }
  66. : { kind: "individual-coding-plan" },
  67. }}
  68. />
  69. <CodingPlanStatusPanel
  70. providerId={family.startPlanProviderId}
  71. providerName={family.id}
  72. status={status}
  73. statusLabelId={
  74. state === "expired" ? "settings.modelProvider.startPlan.status.loginExpired" : undefined
  75. }
  76. loginActionVisible
  77. loginActionPlacement="trailing"
  78. onLogin={() => setActions((x) => x + 1)}
  79. onRetry={state === "unavailable" ? () => setActions((x) => x + 1) : undefined}
  80. startPlanPreviewVisible={false}
  81. planLevel="Start"
  82. subscriptionDetails={
  83. status === "purchased"
  84. ? [
  85. {
  86. productId: "start",
  87. productName: "Start Plan",
  88. purchaseTime: null,
  89. beginTime: null,
  90. expireTime: null,
  91. entitlements:
  92. state === "pending"
  93. ? [
  94. {
  95. entitlementId: "scheduled",
  96. effectiveTime: new Date(Date.now() + 3600000).toISOString(),
  97. },
  98. ]
  99. : [],
  100. },
  101. ]
  102. : []
  103. }
  104. quotaLimits={
  105. status === "purchased" && state !== "pending"
  106. ? [
  107. {
  108. type: "tokens",
  109. planId: "start",
  110. number: 3000000,
  111. remaining: state === "empty" ? 0 : 1500000,
  112. usageDetails: [{ modelCode: "GLM-5.3" }],
  113. },
  114. ]
  115. : []
  116. }
  117. />
  118. <p data-testid="model-label">
  119. {formatModelChangeLabel(family.teamCodingPlanProviderId, undefined, "GLM-5.3", intl)} →{" "}
  120. {formatModelChangeLabel(family.startPlanProviderId, undefined, "GLM-5.3", intl)}
  121. </p>
  122. <output data-testid="actions">{actions}</output>
  123. </section>
  124. </main>
  125. );
  126. }
  127. createRoot(document.getElementById("root")!).render(
  128. <ZCodeIntlProvider initialLocale={params.get("locale") === "zh-CN" ? "zh-CN" : "en-US"}>
  129. <TooltipProvider>
  130. <Fixture />
  131. </TooltipProvider>
  132. </ZCodeIntlProvider>,
  133. );