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
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
// under the License.

import { ListingTable } from "@wso2/oxygen-ui";
import { type JSX, useState, useMemo } from "react";
import { type JSX, useState, useMemo, useCallback } from "react";
import { useNavigate } from "react-router";
import { useAsgardeo } from "@asgardeo/react";
import { getNoveraChatEnabled } from "@utils/settingsStorage";
import { useGetProjectCasesPage } from "@api/useGetProjectCasesPage";
import useGetCasesFilters from "@api/useGetCasesFilters";
import FilterPopover, {
Expand Down Expand Up @@ -178,6 +179,16 @@ const CasesTable = ({ projectId }: CasesTableProps): JSX.Element => {
options: field.options,
}));

const handleCreateCase = useCallback(() => {
if (getNoveraChatEnabled()) {
navigate(`/${projectId}/support/chat/describe-issue`);
} else {
navigate(`/${projectId}/support/chat/create-case`, {
state: { skipChat: true },
});
}
}, [navigate, projectId]);

const getDisplayValue = (fieldId: string, value: any): string => {
if (!value) return "";
const field = dynamicFilterFields.find((f) => f.id === fieldId);
Expand Down Expand Up @@ -212,7 +223,7 @@ const CasesTable = ({ projectId }: CasesTableProps): JSX.Element => {
onClearAll={handleClearFilters}
onFilterClick={() => setIsFilterOpen(true)}
onAllCases={() => navigate(`/${projectId}/support/cases`)}
onCreateCase={() => navigate(`/${projectId}/support/chat/create-case`)}
onCreateCase={handleCreateCase}
/>

{/* Cases list */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ const ProjectInformationCard = ({
project?.createdOn ? formatProjectDate(project.createdOn) : "--";
const getType = () => project?.type || "--";
const getSupportTier = () => project?.account?.supportTier || "--";
const getStartDate = () =>
project?.account?.activationDate
? formatProjectDate(project.account.activationDate)
: "--";
const getEndDate = () =>
project?.account?.deactivationDate
? formatProjectDate(project.account.deactivationDate)
: "--";
const getStartDate = () => {
const val = project?.account?.activationDate;
return val?.trim() ? formatProjectDate(val.trim()) : "--";
};
const getEndDate = () => {
const val = project?.account?.deactivationDate;
return val?.trim() ? formatProjectDate(val.trim()) : "--";
};

return (
<Card sx={{ height: "100%" }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
type Theme,
} from "@wso2/oxygen-ui";
import { CirclePlay } from "@wso2/oxygen-ui-icons-react";
import { type JSX } from "react";
import { type JSX, useState } from "react";
import {
CASE_STATUS_ACTIONS,
type CaseStatusPaletteIntent,
Expand All @@ -45,6 +45,7 @@ import {
getAssignedEngineerLabel,
getAvailableCaseActions,
isWithinOpenRelatedCaseWindow,
toPresentContinuousActionLabel,
toPresentTenseActionLabel,
} from "@utils/support";

Expand Down Expand Up @@ -132,6 +133,9 @@ export default function CaseDetailsActionRow({
const { showError } = useErrorBanner();

const patchCase = usePatchCase(projectId, caseId);
const [pendingActionLabel, setPendingActionLabel] = useState<string | null>(
null,
);

const availableActions = getAvailableCaseActions(statusLabel).filter(
(label) => {
Expand Down Expand Up @@ -224,7 +228,8 @@ export default function CaseDetailsActionRow({
const stateKey = getStateKeyForAction(label, caseStates);
const isOpenRelatedCase = label === "Open Related Case";
const canPatch = !isOpenRelatedCase && stateKey != null && !!caseId;
const isThisPending = !isOpenRelatedCase && patchCase.isPending;
const isThisPending =
!isOpenRelatedCase && patchCase.isPending && pendingActionLabel === label;

return (
<Button
Expand All @@ -247,7 +252,8 @@ export default function CaseDetailsActionRow({
isOpenRelatedCase
? onOpenRelatedCase
: canPatch
? () =>
? () => {
setPendingActionLabel(label);
patchCase.mutate(
{ stateKey: stateKey! },
{
Expand All @@ -260,15 +266,21 @@ export default function CaseDetailsActionRow({
"Failed to update case status. Please try again.",
);
},
onSettled: () => {
setPendingActionLabel(null);
},
},
)
);
}
: undefined
}
sx={
getActionButtonSx(theme, paletteIntent) as Record<string, unknown>
}
>
{toPresentTenseActionLabel(label)}
{isThisPending
? toPresentContinuousActionLabel(label)
: toPresentTenseActionLabel(label)}
</Button>
);
})}
Expand Down
20 changes: 20 additions & 0 deletions apps/customer-portal/webapp/src/utils/__tests__/support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
hasDisplayableContent,
stripCustomerPrefixFromReason,
isWithinOpenRelatedCaseWindow,
toPresentContinuousActionLabel,
toPresentTenseActionLabel,
} from "@utils/support";
import type { CaseComment } from "@models/responses";
Expand Down Expand Up @@ -363,6 +364,25 @@ describe("support utils", () => {
});
});

describe("toPresentContinuousActionLabel", () => {
it("should map Closed to Closing...", () => {
expect(toPresentContinuousActionLabel("Closed")).toBe("Closing...");
});
it("should map Reopened to Reopening...", () => {
expect(toPresentContinuousActionLabel("Reopened")).toBe("Reopening...");
});
it("should map Accept Solution to Accepting...", () => {
expect(toPresentContinuousActionLabel("Accept Solution")).toBe(
"Accepting...",
);
});
it("should map Reject Solution to Rejecting...", () => {
expect(toPresentContinuousActionLabel("Reject Solution")).toBe(
"Rejecting...",
);
});
});

describe("getAttachmentFileCategory", () => {
it("should return image for png, jpg, gif, webp, svg", () => {
expect(getAttachmentFileCategory("photo.png", "")).toBe("image");
Expand Down
18 changes: 18 additions & 0 deletions apps/customer-portal/webapp/src/utils/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,24 @@ export function toPresentTenseActionLabel(label: string): string {
return map[label] ?? label;
}

/**
* Maps action labels to present continuous for loading state (e.g., "Closed" -> "Closing...").
*
* @param label - Action label (e.g., "Closed", "Accept Solution").
* @returns {string} Present continuous label with ellipsis.
*/
export function toPresentContinuousActionLabel(label: string): string {
const map: Record<string, string> = {
Closed: "Closing...",
Reopened: "Reopening...",
"Waiting on WSO2": "Waiting on WSO2...",
"Waiting On WSO2": "Waiting on WSO2...",
Comment on lines +844 to +845

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have 02 different conventions to these keys? on and On?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of data inconsisistensy , will adress in later

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue to track this
#244

"Accept Solution": "Accepting...",
"Reject Solution": "Rejecting...",
};
return map[label] ?? `${label}...`;
}

/** Maps action labels (from getAvailableCaseActions) to caseState labels for lookup. */
export const ACTION_TO_CASE_STATE_LABEL: Record<string, string> = {
Closed: "Closed",
Expand Down