Skip to content

Commit

Permalink
rename variables and delete comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pachonjcl committed Jun 12, 2024
1 parent f98f025 commit 7807576
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const AuditLogTab: FC<IProps> = ({ label, ...rest }) => {
getValueForStatus={valuesForStatus}
progressBarLabels={statusLabels}
mutate={mutateEntity}
recordType={entityType}
entityType={entityType}
refresh={() => {
refetch();
loadEntityList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from "classnames";
import { Dispatch, SetStateAction, useState } from "react";
import { When } from "react-if";

import Dropdown from "@/components/elements/Inputs/Dropdown/Dropdown";
import Notification from "@/components/elements/Notification/Notification";
Expand All @@ -12,6 +13,7 @@ import { recentRequestData } from "@/utils/statusUtils";

import StatusDisplay from "../../PolygonReviewTab/components/PolygonStatus/StatusDisplay";
import { AuditLogEntity } from "../constants/types";
import { getRequestPathParam } from "../utils/util";

const SiteAuditLogEntityStatusSide = ({
refresh,
Expand All @@ -20,14 +22,14 @@ const SiteAuditLogEntityStatusSide = ({
selectedPolygon,
setSelectedPolygon,
auditLogData,
recordType = "Polygon",
entityType = "Polygon", //useAditLogEntity
mutate,
getValueForStatus,
progressBarLabels,
tab,
checkPolygonsSite
}: {
recordType?: AuditLogEntity;
entityType: AuditLogEntity;
refresh?: () => void;
record?: any;
polygonList?: any[];
Expand All @@ -44,7 +46,7 @@ const SiteAuditLogEntityStatusSide = ({
const recentRequest = auditLogData?.find(
(item: AuditStatusResponse) => item.type == "change-request" && item.is_active
);
const mutateUpload = recordType === "Project" ? usePostV2AuditStatusENTITYUUID : usePostV2AuditStatusENTITYUUID;
const mutateUpload = entityType === "Project" ? usePostV2AuditStatusENTITYUUID : usePostV2AuditStatusENTITYUUID;
const { mutate: upload } = mutateUpload({
onSuccess: () => {
setOpen(true);
Expand All @@ -59,45 +61,42 @@ const SiteAuditLogEntityStatusSide = ({
upload?.({
pathParams: {
uuid: record?.uuid,
entity: recordType === "Polygon" ? "site-polygon" : recordType
entity: getRequestPathParam(entityType)
},
body: {
// entity_uuid: record?.uuid,
status: record?.status,
// entity: recordType === "Polygon" ? "SitePolygon" : recordType,
comment: "",
type: "change-request",
// is_active: false,
request_removed: true
}
});
};

return (
<div className="flex flex-col gap-6 overflow-visible">
{polygonList && polygonList?.length > 0 && (
<When condition={polygonList?.length}>
<Dropdown
label={`Select ${recordType}`}
label={`Select ${entityType}`}
labelVariant="text-16-bold"
labelClassName="capitalize"
optionsClassName="max-w-full"
value={[selectedPolygon?.uuid ?? ""]}
placeholder={`Select ${recordType}`}
placeholder={`Select ${entityType}`}
options={polygonList!}
onChange={e => {
setSelectedPolygon && setSelectedPolygon(polygonList?.find(item => item?.uuid === e[0]));
}}
/>
)}
<Text variant="text-16-bold">{`${recordType} Status`}</Text>
</When>
<Text variant="text-16-bold">{`${entityType} Status`}</Text>
<StepProgressbar
color="secondary"
value={(getValueForStatus && getValueForStatus(record?.status)) ?? 0}
labels={progressBarLabels}
classNameLabels="min-w-[99px] "
className={classNames("w-[98%] pl-[1%]", recordType === "Polygon" && "pl-[6%]")}
className={classNames("w-[98%] pl-[1%]", entityType === "Polygon" && "pl-[6%]")}
/>
{recentRequest && (
<When condition={!!recentRequest}>
<div className="flex flex-col gap-2 rounded-xl border border-yellow-500 bg-yellow p-3">
<div>
<div className="flex items-baseline justify-between">
Expand All @@ -106,14 +105,14 @@ const SiteAuditLogEntityStatusSide = ({
Remove
</button>
</div>
<Text variant="text-14-light">{recentRequestData(recentRequest)}</Text>
<Text variant="text-14-light">{recentRequestData(recentRequest!)}</Text>
</div>
<Text variant="text-14-semibold">{recentRequest?.comment}</Text>
</div>
)}
</When>
<StatusDisplay
titleStatus={recordType}
name={recordType}
titleStatus={entityType}
name={entityType}
refresh={refresh}
mutate={mutate}
record={record}
Expand Down
8 changes: 8 additions & 0 deletions src/admin/components/ResourceTabs/AuditLogTab/utils/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AuditLogEntity } from "../constants/types";

export const getRequestPathParam = (entityType: AuditLogEntity) => {
if (entityType === "Polygon") {
return "site-polygon";
}
return entityType.toLocaleLowerCase();
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ModalConfirm from "@/components/extensive/Modal/ModalConfirm";
import { useModalContext } from "@/context/modal.provider";

import { AuditLogEntity } from "../../../AuditLogTab/constants/types";
import { getRequestPathParam } from "../../../AuditLogTab/utils/util";

const menuPolygonOptions = [
{
Expand Down Expand Up @@ -144,6 +145,12 @@ const StatusDisplay = ({
</Text>
);

const onFinallyRequest = () => {
refresh && refresh();
reloadEntity && reloadEntity();
closeModal();
};

const openFormModalHandlerStatus = () => {
openModal(
<ModalConfirm
Expand All @@ -160,7 +167,7 @@ const StatusDisplay = ({
await mutate({
pathParams: {
uuid: record?.uuid,
entity: titleStatus.toLowerCase() == "polygon" ? "site-polygon" : titleStatus.toLowerCase()
entity: getRequestPathParam(titleStatus)
},
body: {
status: option?.status,
Expand Down Expand Up @@ -199,9 +206,7 @@ const StatusDisplay = ({
}, 3000);
console.error(e);
} finally {
refresh && refresh();
reloadEntity && reloadEntity();
closeModal;
onFinallyRequest();
}
}}
/>
Expand Down Expand Up @@ -259,9 +264,7 @@ const StatusDisplay = ({
}, 3000);
console.error(e);
} finally {
refresh && refresh();
reloadEntity && reloadEntity();
closeModal;
onFinallyRequest();
}
}}
/>
Expand Down
8 changes: 1 addition & 7 deletions src/components/elements/CommentaryBox/CommentaryBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState } from "react";
import { When } from "react-if";

import { AuditLogEntity } from "@/admin/components/ResourceTabs/AuditLogTab/constants/types";
import { getRequestPathParam } from "@/admin/components/ResourceTabs/AuditLogTab/utils/util";
import Button from "@/components/elements/Button/Button";
import TextArea from "@/components/elements/Inputs/textArea/TextArea";
import Text from "@/components/elements/Text/Text";
Expand All @@ -26,13 +27,6 @@ export interface CommentaryBoxProps {
entity?: AuditLogEntity;
}

const getRequestPathParam = (entityType: AuditLogEntity) => {
if (entityType === "Polygon") {
return "site-polygon";
}
return entityType.toLocaleLowerCase();
};

const CommentaryBox = (props: CommentaryBoxProps) => {
const { name, lastName, buttonSendOnBox } = props;
const t = useT();
Expand Down

0 comments on commit 7807576

Please sign in to comment.