Files
Stirling-PDF/frontend/editor/src/proprietary/components/shared/UpdateSeatsModal.tsx
T
0a50e765b7 Restructure/frontend editor (#6404)
## Move editor under `frontend/editor/`

Pure restructure: `frontend/` becomes the workspace, `frontend/editor/`
holds
  the PDF editor. 1775 file renames + 40 wiring edits. No logic changes.

  ### Why

`frontend/` is currently the editor — its `src/`, `public/`,
`src-tauri/`,
  config files all sit at the root. Promoting `frontend/` to a
workspace and putting the editor in a sibling folder leaves room for
future
apps to drop in alongside it, sharing one `package.json` /
`node_modules` /
  lint config / Storybook.

  ### What moves

  frontend/
  ├── editor/                ← NEW: everything editor-specific
  │   ├── src/               ← was frontend/src/
  │   ├── public/            ← was frontend/public/
  │   ├── src-tauri/         ← was frontend/src-tauri/
│ ├── index.html, vite.config.ts, vitest.config.ts, playwright.config.ts
  │   ├── tsconfig*.json, tailwind.config.js, postcss.config.js
  │   ├── scripts/
  │   ├── .env, .env.desktop, .env.saas
  │   └── DeveloperGuide.md
├── package.json, package-lock.json, node_modules/ ← workspace install
  ├── eslint.config.mjs, .prettierrc, .prettierignore ← shared tooling
  ├── .gitignore
  └── README.md

  ### Wiring edits (40 files)

  - `.taskfiles/frontend.yml`, `desktop.yml`, `e2e.yml`
  - `build.gradle`, `app/core/build.gradle`
- `eslint.config.mjs`, `frontend/package.json`, `.gitignore`,
`.prettierignore`
  - `docker/frontend/Dockerfile`
  - 8 `.github/workflows/*.yml`, plus `.github/dependabot.yml`,
    `.github/config/.files.yaml`, `.github/labeler-config-srvaroa.yml`
  - `scripts/translations/**`
- Docs: `AGENTS.md`, `CLAUDE.md`, `ADDING_TOOLS.md`,
`DeveloperGuide.md`,
`WINDOWS_SIGNING.md`, `devGuide/HowToAddNewLanguage.md`,
`frontend/README.md`,
    `frontend/editor/DeveloperGuide.md`

Plus 3 renamed + edited: `editor/vite.config.ts` (env path +
node_modules
  walk-up), `editor/scripts/setup-env.mts` (renamed from `.ts` for
`import.meta.url`), `editor/scripts/build-provisioner.mjs` (resolve
src-tauri
  relative to script).

  ### Verification

  | Check | Result |
  |---|---|
  | `task frontend:typecheck:all` (6 variants) | exit 0 |
  | `task frontend:lint` (eslint + dpdm) | exit 0 |
  | `task frontend:format:check` | exit 0 |
  | `task frontend:test` | 657 tests pass, 50 files |
| `task frontend:build:{core,proprietary,saas,desktop,prototypes}` | all
green |
| `task desktop:build` | full Tauri pipeline →
`Stirling-PDF_2.11.0_x64_en-US.msi` |
  | `playwright test --list --project=stubbed` | 172 tests discovered |

`task desktop:build` exercises the heaviest path — Rust + WiX + MSI
bundle
against the moved `editor/src-tauri/`. If anything in the restructure
was
  wrong it wouldn't have built.

  ### Test plan

  - [ ] `frontend-validation.yml` green
  - [ ] `e2e-stubbed.yml` green
  - [ ] `tauri-build.yml` green on at least one platform
  - [ ] `check_toml.yml` runs on a translation-touching PR

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
2026-05-22 13:40:34 +01:00

227 lines
5.8 KiB
TypeScript

import React, { useState, useEffect } from "react";
import {
Modal,
Button,
Text,
Alert,
Loader,
Stack,
Group,
NumberInput,
} from "@mantine/core";
import { useTranslation } from "react-i18next";
import { Z_INDEX_OVER_CONFIG_MODAL } from "@app/styles/zIndex";
interface UpdateSeatsModalProps {
opened: boolean;
onClose: () => void;
currentSeats: number;
minimumSeats: number;
_onSuccess?: () => void;
onError?: (error: string) => void;
onUpdateSeats?: (newSeats: number) => Promise<string>; // Returns billing portal URL
}
type UpdateState = {
status: "idle" | "loading" | "error";
error?: string;
};
const UpdateSeatsModal: React.FC<UpdateSeatsModalProps> = ({
opened,
onClose,
currentSeats,
minimumSeats,
_onSuccess,
onError,
onUpdateSeats,
}) => {
const { t } = useTranslation();
const [state, setState] = useState<UpdateState>({ status: "idle" });
const [newSeatCount, setNewSeatCount] = useState<number>(minimumSeats);
// Reset seat count when modal opens
useEffect(() => {
if (opened) {
setNewSeatCount(minimumSeats);
setState({ status: "idle" });
}
}, [opened, minimumSeats]);
const handleUpdateSeats = async () => {
if (!onUpdateSeats) {
setState({
status: "error",
error: "Update function not provided",
});
return;
}
if (newSeatCount < minimumSeats) {
setState({
status: "error",
error: t(
"billing.seatCountTooLow",
"Seat count must be at least {{minimum}} (current number of users)",
{
minimum: minimumSeats,
},
),
});
return;
}
if (newSeatCount === currentSeats) {
setState({
status: "error",
error: t(
"billing.seatCountUnchanged",
"Please select a different seat count",
),
});
return;
}
try {
setState({ status: "loading" });
// Call the update function (will call manage-billing)
const portalUrl = await onUpdateSeats(newSeatCount);
// Redirect to Stripe billing portal
console.log("Redirecting to Stripe billing portal:", portalUrl);
window.location.href = portalUrl;
// Note: No need to call onSuccess here since we're redirecting
// The return flow will handle success notification
} catch (err) {
const errorMessage =
err instanceof Error ? err.message : "Failed to update seat count";
setState({
status: "error",
error: errorMessage,
});
onError?.(errorMessage);
}
};
const handleClose = () => {
setState({ status: "idle" });
setNewSeatCount(currentSeats);
onClose();
};
const renderContent = () => {
if (state.status === "loading") {
return (
<Stack align="center" justify="center" style={{ padding: "2rem 0" }}>
<Loader size="lg" />
<Text size="sm" c="dimmed" mt="md">
{t("billing.preparingUpdate", "Preparing seat update...")}
</Text>
</Stack>
);
}
return (
<Stack gap="lg">
{state.status === "error" && (
<Alert color="red" title={t("common.error", "Error")}>
{state.error}
</Alert>
)}
<Stack gap="md" mt="md">
<Group justify="space-between">
<Text size="sm" fw={500}>
{t("billing.currentSeats", "Current Seats")}:
</Text>
<Text size="sm" fw={600}>
{currentSeats}
</Text>
</Group>
<Group justify="space-between">
<Text size="sm" fw={500}>
{t("billing.minimumSeats", "Minimum Seats")}:
</Text>
<Text size="sm" c="dimmed">
{minimumSeats} {t("billing.basedOnUsers", "(current users)")}
</Text>
</Group>
</Stack>
<NumberInput
label={t("billing.newSeatCount", "New Seat Count")}
description={t(
"billing.newSeatCountDescription",
"Select the number of seats for your enterprise license",
)}
value={newSeatCount}
onChange={(value) =>
setNewSeatCount(typeof value === "number" ? value : minimumSeats)
}
min={minimumSeats}
max={10000}
step={1}
size="md"
styles={{
input: {
fontSize: "1.5rem",
fontWeight: 500,
textAlign: "center",
},
}}
/>
<Alert
color="blue"
title={t("billing.whatHappensNext", "What happens next?")}
>
<Text size="sm">
{t(
"billing.stripePortalRedirect",
"You will be redirected to Stripe's billing portal to review and confirm the seat change. The prorated amount will be calculated automatically.",
)}
</Text>
</Alert>
<Group justify="flex-end" gap="sm">
<Button variant="outline" onClick={handleClose}>
{t("common.cancel", "Cancel")}
</Button>
<Button
onClick={handleUpdateSeats}
disabled={
newSeatCount === currentSeats || newSeatCount < minimumSeats
}
>
{t("billing.updateSeats", "Update Seats")}
</Button>
</Group>
</Stack>
);
};
return (
<Modal
opened={opened}
onClose={handleClose}
title={
<Text fw={600} size="lg">
{t("billing.updateEnterpriseSeats", "Update Enterprise Seats")}
</Text>
}
size="md"
centered
withCloseButton={true}
closeOnEscape={true}
closeOnClickOutside={false}
zIndex={Z_INDEX_OVER_CONFIG_MODAL}
>
{renderContent()}
</Modal>
);
};
export default UpdateSeatsModal;