Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions apps/csm-portal/webapp/src/api/backend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,22 +561,23 @@ interface BeCaseUpdateNever {
bestCaseFixEta?: never;
mostLikelyFixEta?: never;
worstCaseFixEta?: never;
addPublicComment?: never;
product?: never;
publicTicket?: never;
}

/**
* Request body for `PATCH /cases/{id}` (mirrors the entity `UpdateCaseRequest`).
* **Exactly one** of `state` / `severity` / `workState` / `assigneeEmail` /
* `watchList` / `parentId` / `subject` / `description` / `deploymentId` /
* `deployedProductId` / `relatedCaseId` / `autocloseHoldUntil` /
* `bestCaseFixEta` / `mostLikelyFixEta` / `worstCaseFixEta` is sent per call —
* the backend rejects zero or more than one. Encoded as a discriminated union
* (each variant carries every other field as `never`, via
* {@link BeCaseUpdateNever}) so the exactly-one-field contract is enforced at
* compile time, not just in docs. `assigneeEmail`, `watchList`, `parentId`,
* and `autocloseHoldUntil` are supported **only** for the ServiceNow data
* source. `workState` is only accepted while the case is `work_in_progress`.
* `bestCaseFixEta` / `mostLikelyFixEta` / `worstCaseFixEta` are internal-only
* estimates, never shared with the customer.
* `deployedProductId` / `relatedCaseId` / `autocloseHoldUntil` / the combined
* fix-ETA variant (below) is sent per call — the backend rejects zero or more
* than one. Encoded as a discriminated union (each variant carries every
* other field as `never`, via {@link BeCaseUpdateNever}) so the
* exactly-one-field contract is enforced at compile time, not just in docs.
* `assigneeEmail`, `watchList`, `parentId`, and `autocloseHoldUntil` are
* supported **only** for the ServiceNow data source. `workState` is only
* accepted while the case is `work_in_progress`.
*/
export type BeCaseUpdatePayload =
| (Omit<BeCaseUpdateNever, "state"> & {
Expand Down Expand Up @@ -615,12 +616,32 @@ export type BeCaseUpdatePayload =
* `autoclosureStep` is not directly settable.
*/
| (Omit<BeCaseUpdateNever, "autocloseHoldUntil"> & { autocloseHoldUntil: string })
/** Sets the internal-only best-case fix estimate (date-only, "YYYY-MM-DD"). */
| (Omit<BeCaseUpdateNever, "bestCaseFixEta"> & { bestCaseFixEta: string })
/** Sets the internal-only most-likely fix estimate (date-only, "YYYY-MM-DD"). */
| (Omit<BeCaseUpdateNever, "mostLikelyFixEta"> & { mostLikelyFixEta: string })
/** Sets the internal-only worst-case fix estimate (date-only, "YYYY-MM-DD"). */
| (Omit<BeCaseUpdateNever, "worstCaseFixEta"> & { worstCaseFixEta: string });
/**
* Sets any combination of the three internal-only fix-ETA estimates
* (date-only "YYYY-MM-DD") in one call — unlike the other variants, this is
* a **combined** field, so at least one of the three must be present, but
* all three are independently optional. When `addPublicComment` is true,
* the backend also posts a customer-visible comment built from `product` /
* `publicTicket` / the estimate(s) above to the case's comment thread; that
* mode requires at least one estimate plus non-empty `product` and
* `publicTicket`.
*/
| (Omit<
BeCaseUpdateNever,
| "bestCaseFixEta"
| "mostLikelyFixEta"
| "worstCaseFixEta"
| "addPublicComment"
| "product"
| "publicTicket"
> & {
bestCaseFixEta?: string;
mostLikelyFixEta?: string;
worstCaseFixEta?: string;
addPublicComment?: boolean;
product?: string;
publicTicket?: string;
});

/** A user in the case watch list, as echoed by `PATCH /cases/{id}`. */
export interface BeWatchListUser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import { Phone, Plus, RefreshCw } from "@wso2/oxygen-ui-icons-react";
import { useEffect, useState, type JSX } from "react";
import type { BeCallRequestView, BeCallRequestStateKey } from "@api/backend/types";
import type { Severity } from "@features/csm-dashboard/types/abtDashboard";
import type { CaseState, Severity } from "@features/csm-dashboard/types/abtDashboard";
import {
useGetCsmCaseCallRequests,
usePostCsmCaseCallRequest,
Expand All @@ -40,6 +40,7 @@ import {
import {
ALL_CALL_REQUEST_STATES,
CALL_REQUEST_STATE_LABEL,
callRequestCaseStateBlockReason,
type CallRequestAgentAction,
resolveCallRequestStateKey,
} from "@features/csm-cases/utils/callRequestState";
Expand All @@ -58,6 +59,13 @@ interface CallRequestsWidgetProps {
caseId: string;
/** Case severity (S0-S4) — passed to the create dialog to enforce the lead-time rule. */
severity?: Severity;
/**
* Case's current state — the data source only accepts a call request while
* the case is in one of a fixed set of states. Gates both the "Create call
* request" trigger and the dialog's submit action; passed straight from the
* live case-detail data so it stays in sync if the case's state changes.
*/
caseState?: CaseState;
/** True to pop the "Create call request" dialog from outside the widget
* (e.g. the case action bar's "Request a call" item). One-shot: the
* widget calls `onAutoOpenCreateHandled` once it has acted on it, so the
Expand All @@ -77,6 +85,7 @@ interface CallRequestsWidgetProps {
export function CallRequestsWidget({
caseId,
severity,
caseState,
autoOpenCreate,
onAutoOpenCreateHandled,
isClosed,
Expand All @@ -96,15 +105,17 @@ export function CallRequestsWidget({
const [createOpen, setCreateOpen] = useState(false);
const [createError, setCreateError] = useState<string | null>(null);

const stateBlockReason = callRequestCaseStateBlockReason(caseState);

useEffect(() => {
if (autoOpenCreate) {
if (!isClosed) {
if (!isClosed && !stateBlockReason) {
// eslint-disable-next-line react-hooks/set-state-in-effect -- syncs the dialog open to an external one-shot trigger from the case action bar
setCreateOpen(true);
}
onAutoOpenCreateHandled?.();
}
}, [autoOpenCreate, isClosed, onAutoOpenCreateHandled]);
}, [autoOpenCreate, isClosed, stateBlockReason, onAutoOpenCreateHandled]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// Dialog targets — only one dialog is ever open at a time, driven by which
// action was clicked on a row.
Expand Down Expand Up @@ -160,6 +171,10 @@ export function CallRequestsWidget({
assignee?: string;
}) => {
if (!scheduleTarget) return;
if (stateBlockReason) {
setActionError(stateBlockReason);
return;
}
setActionError(null);
try {
await patchCallRequest.mutateAsync({
Expand Down Expand Up @@ -287,14 +302,20 @@ export function CallRequestsWidget({
))}
</Select>
</FormControl>
<Tooltip title={isClosed ? "This case is closed — it's read-only." : ""}>
<Tooltip
title={
isClosed
? "This case is closed — it's read-only."
: (stateBlockReason ?? "")
}
>
<span>
<Button
size="small"
variant="contained"
startIcon={<Plus size={14} />}
onClick={() => setCreateOpen(true)}
disabled={isClosed}
disabled={isClosed || !!stateBlockReason}
sx={{ textTransform: "none" }}
>
Create call request
Expand Down Expand Up @@ -362,6 +383,7 @@ export function CallRequestsWidget({
submitting={postCallRequest.isPending}
error={createError}
severity={severity}
caseState={caseState}
onClose={() => {
setCreateOpen(false);
setCreateError(null);
Expand All @@ -376,6 +398,7 @@ export function CallRequestsWidget({
isReschedule={!!isReschedule}
submitting={patchCallRequest.isPending}
error={actionError}
stateBlockReason={stateBlockReason}
onClose={() => {
setScheduleTarget(null);
setActionError(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ interface SecondaryItem {
* Kept here even though a Tasks tab exists: that tab is
* still `hidden` in CsmCaseDetailPage's TAB_DEFS, so this
* menu item is the only reachable entry point today.
* - Set fix ETA → PATCH /cases/{id} { bestCaseFixEta | mostLikelyFixEta |
* worstCaseFixEta }, see SetFixEtaDialog.tsx
* - Set fix ETA → PATCH /cases/{id} { bestCaseFixEta?, mostLikelyFixEta?,
* worstCaseFixEta?, addPublicComment?, product?,
* publicTicket? } combined in one call, see SetFixEtaDialog.tsx
* - Log time → ISSU-017
* - Change severity → PATCH /cases/{id} { severity }, already fully
* backend-supported (see ChangeSeverityDialog.tsx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
} from "@wso2/oxygen-ui";
import { Plus } from "@wso2/oxygen-ui-icons-react";
import { useState, type JSX } from "react";
import type { Severity } from "@features/csm-dashboard/types/abtDashboard";
import type { CaseState, Severity } from "@features/csm-dashboard/types/abtDashboard";
import { callRequestCaseStateBlockReason } from "@features/csm-cases/utils/callRequestState";
import {
formatDateTimeLocal,
parseDateTimeLocal,
Expand Down Expand Up @@ -168,6 +169,13 @@ export interface CreateDialogProps {
error: string | null;
/** Case severity (S0-S4) — drives the minimum lead time for each proposed slot. */
severity?: Severity;
/**
* Case's current state — the data source only accepts a call request while
* the case is in one of a fixed set of states (see
* `callRequestCaseStateBlockReason`). Undefined skips this FE-side check
* (the backend still enforces it either way).
*/
caseState?: CaseState;
onClose: () => void;
onSubmit: (reason: string, utcTimes: string[], durationInMinutes: number) => void;
}
Expand All @@ -181,6 +189,7 @@ export function CreateCallRequestDialog({
submitting,
error,
severity,
caseState,
onClose,
onSubmit,
}: CreateDialogProps): JSX.Element {
Expand Down Expand Up @@ -223,7 +232,13 @@ export function CreateCallRequestDialog({
durationNum >= MIN_DURATION_MINUTES &&
durationNum <= MAX_DURATION_MINUTES;

// Re-derived on every render (not memoized on mount) so this stays in sync
// if the case's state changes while the dialog is open -- `caseState` comes
// from the live case-detail data, not a snapshot taken when the dialog opened.
const stateBlockReason = callRequestCaseStateBlockReason(caseState);

const canSubmit =
!stateBlockReason &&
reason.trim().length > 0 &&
utcTimes.length > 0 &&
utcTimes.length <= MAX_TIME_SLOTS &&
Expand All @@ -240,6 +255,11 @@ export function CreateCallRequestDialog({
<DialogTitle>Create a call request</DialogTitle>
<DialogContent>
<Box sx={{ display: "flex", flexDirection: "column", gap: 2, pt: 0.5 }}>
{stateBlockReason && (
<Typography variant="body2" color="error">
{stateBlockReason}
</Typography>
)}
{error && (
<Typography variant="body2" color="error">
{error}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export interface ScheduleCallDialogProps {
isReschedule: boolean;
submitting: boolean;
error: string | null;
/**
* Non-null when the parent case's current state doesn't allow scheduling a
* call (same rule as call-request creation — see
* `callRequestCaseStateBlockReason`). Displays the reason and disables
* submit; the caller should also reject the mutation defensively.
*/
stateBlockReason?: string | null;
onClose: () => void;
onSubmit: (input: {
meetingDate: string;
Expand All @@ -81,6 +88,7 @@ export function ScheduleCallDialog({
isReschedule,
submitting,
error,
stateBlockReason,
onClose,
onSubmit,
}: ScheduleCallDialogProps): JSX.Element {
Expand Down Expand Up @@ -139,7 +147,7 @@ export function ScheduleCallDialog({
const canSubmit = durationValid && customTimeValid && !!meetingDate;

const handleSubmit = () => {
if (!canSubmit || !meetingDate) return;
if (!canSubmit || !meetingDate || stateBlockReason) return;
// Reject a time in the past (immediate feedback; the backing data source
// enforces a stricter lead time). Time is read in the handler, not render.
if (isPastDateTime(new Date(meetingDate))) {
Expand All @@ -159,6 +167,11 @@ export function ScheduleCallDialog({
<DialogTitle>{isReschedule ? "Reschedule call" : "Schedule call"}</DialogTitle>
<DialogContent>
<Box sx={{ display: "flex", flexDirection: "column", gap: 2, pt: 0.5 }}>
{stateBlockReason && (
<Typography variant="body2" color="error">
{stateBlockReason}
</Typography>
)}
{(error || pastError) && (
<Typography variant="body2" color="error">
{error ?? "Meeting time must be in the future."}
Expand Down Expand Up @@ -272,7 +285,7 @@ export function ScheduleCallDialog({
<Button
variant="contained"
onClick={handleSubmit}
disabled={!canSubmit || submitting}
disabled={!canSubmit || submitting || !!stateBlockReason}
loading={submitting}
>
{isReschedule ? "Reschedule" : "Schedule"}
Expand Down
Loading