Skip to content

Commit

Permalink
Update helpdesk component to work with updated data returned by the s…
Browse files Browse the repository at this point in the history
…erver app's help API (allows better searching/display via rebate id alone)
  • Loading branch information
courtneymyers committed Nov 4, 2024
1 parent b06eb16 commit 443aff7
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions app/client/src/routes/helpdesk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,20 @@ import {
useRebateYearActions,
} from "@/contexts/rebateYear";

type Response =
| {
formSchema: null;
formio: null;
bap: BapSubmissionData;
}
| {
formSchema: { url: string; json: object };
formio:
type Response = {
rebateId: string | null;
formSchema: { url: string; json: object } | null;
formio:
| (
| FormioFRF2022Submission
| FormioPRF2022Submission
| FormioCRF2022Submission
| FormioFRF2023Submission
| FormioPRF2023Submission;
bap: BapSubmissionData;
};
| FormioPRF2023Submission
)
| null;
bap: BapSubmissionData | null;
};

type SubmissionAction = {
_id: string; // MongoDB ObjectId string
Expand Down Expand Up @@ -120,22 +118,22 @@ function ResultTableRow(props: {
DraftSubmission,
unknown
>;
lastSearchedText: string;
formType: FormType;
rebateId: string | null;
formio:
| FormioFRF2022Submission
| FormioPRF2022Submission
| FormioCRF2022Submission
| FormioFRF2023Submission
| FormioPRF2023Submission;
bap: BapSubmissionData;
bap: BapSubmissionData | null;
}) {
const {
setFormDisplayed,
setActionsData,
submissionMutation,
lastSearchedText,
formType,
rebateId,
formio,
bap,
} = props;
Expand Down Expand Up @@ -180,11 +178,11 @@ function ResultTableRow(props: {
const date = formatDate(formio.modified);
const time = formatTime(formio.modified);

const bapId = lastSearchedText.length === 6 ? bap.rebateId : bap.mongoId;
const bapInternalStatus = bap?.status || "";
const bapReimbursementNeeded = bap?.reimbursementNeeded || false;

const bapInternalStatus = bap.status || "";
const bapStatus = bapStatusMap[rebateYear][formType].get(bapInternalStatus);
const formioStatus = formioStatusMap.get(formio.state);
const bapReimbursementNeeded = bap.reimbursementNeeded || false;

const needsEdits = submissionNeedsEdits({ formio, bap });

Expand All @@ -199,9 +197,7 @@ function ResultTableRow(props: {
? "Edits Requested"
: crfNeedsReimbursement
? "Reimbursement Needed"
: bapStatusMap[rebateYear][formType].get(bapInternalStatus) ||
formioStatus ||
"";
: bapStatus || formioStatus || "";

const nameField = formioNameField[rebateYear][formType];
const emailField = formioEmailField[rebateYear][formType];
Expand Down Expand Up @@ -229,11 +225,11 @@ function ResultTableRow(props: {
</span>
</button>
</th>
<td>{bapId || mongoId}</td>
<td>{rebateId || mongoId}</td>
<td>
{status}

{!bapId && status === "Submitted" && (
{!bap && status === "Submitted" && (
<span className="margin-left-2">
<button
className="usa-button font-sans-2xs margin-right-0 padding-x-105 padding-y-1"
Expand Down Expand Up @@ -387,7 +383,6 @@ export function Helpdesk() {

const [formType, setFormType] = useState<FormType>("frf");
const [searchText, setSearchText] = useState("");
const [lastSearchedText, setLastSearchedText] = useState("");
const [resultDisplayed, setResultDisplayed] = useState(false);
const [formDisplayed, setFormDisplayed] = useState(false);
const [actionsData, setActionsData] = useState<{
Expand Down Expand Up @@ -426,7 +421,12 @@ export function Helpdesk() {
},
});

const { formSchema, formio, bap } = submissionQuery.data ?? {};
const { rebateId, formSchema, formio, bap } = submissionQuery.data ?? {
rebateId: null,
formSchema: null,
formio: null,
bap: null,
};

if (helpdeskAccess === "pending") {
return <Loading />;
Expand Down Expand Up @@ -557,7 +557,6 @@ export function Helpdesk() {
onSubmit={(ev) => {
ev.preventDefault();
if (searchText === "") return;
setLastSearchedText(searchText);
setFormDisplayed(false);
setActionsData({ fetched: false, results: [] });
submissionQuery.refetch();
Expand Down Expand Up @@ -590,7 +589,7 @@ export function Helpdesk() {
<Loading />
) : submissionQuery.isError ? (
<Message type="error" text={messages.helpdeskSubmissionSearchError} />
) : submissionQuery.isSuccess && !!formio && !!bap && resultDisplayed ? (
) : submissionQuery.isSuccess && !!formio && resultDisplayed ? (
<>
<div className="usa-table-container--scrollable" tabIndex={0}>
<table
Expand All @@ -603,7 +602,7 @@ export function Helpdesk() {
<span className="usa-sr-only">Open</span>
</th>

{lastSearchedText.length === 6 ? (
{rebateId ? (
<th scope="col">
<TextWithTooltip
text="Rebate ID"
Expand Down Expand Up @@ -668,8 +667,8 @@ export function Helpdesk() {
setFormDisplayed={setFormDisplayed}
setActionsData={setActionsData}
submissionMutation={submissionMutation}
lastSearchedText={lastSearchedText}
formType={formType}
rebateId={rebateId}
formio={formio}
bap={bap}
/>
Expand Down Expand Up @@ -732,20 +731,19 @@ export function Helpdesk() {
</svg>
</div>
<div className="usa-icon-list__content">
<strong>MongoDB Object ID:</strong>{" "}
{bap.mongoId || formio._id}
<strong>MongoDB Object ID:</strong> {formio._id}
</div>
</li>

{bap.rebateId && (
{rebateId && (
<li className="usa-icon-list__item">
<div className="usa-icon-list__icon text-primary">
<svg className="usa-icon" aria-hidden="true" role="img">
<use href={`${icons}#local_offer`} />
</svg>
</div>
<div className="usa-icon-list__content">
<strong>Rebate ID:</strong> {bap.rebateId}
<strong>Rebate ID:</strong> {rebateId}
</div>
</li>
)}
Expand Down

0 comments on commit 443aff7

Please sign in to comment.