Skip to content

Commit

Permalink
[TM-1188] update audit log ux (#499)
Browse files Browse the repository at this point in the history
* [TM-1188] update audit log to close and save

* [TM-1188] keep audit log to polygons

* [TM-1188] update text for action table

* [TM-1188] improve get columntitle and size
  • Loading branch information
LimberHope authored Sep 23, 2024
1 parent df5f061 commit 9d0f6ba
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
6 changes: 4 additions & 2 deletions src/admin/apiProvider/utils/entryFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export const convertDateFormat = (value: any) => {
const formattedDay = dateObject.getUTCDate().toString().padStart(2, "0");
const formattedMonth = (dateObject.getUTCMonth() + 1).toString().padStart(2, "0");
const formattedYear = dateObject.getUTCFullYear();
const formattedDate = `${formattedDay}/${formattedMonth}/${formattedYear}`;
const formattedHours = dateObject.getUTCHours().toString().padStart(2, "0");
const formattedMinutes = dateObject.getUTCMinutes().toString().padStart(2, "0");
const formattedDate = `${formattedDay}/${formattedMonth}/${formattedYear} ${formattedHours}:${formattedMinutes}`;
return formattedDate;
}
return format(new Date(value), "dd/MM/yyyy");
return format(new Date(value), "dd/MM/yyyy HH:mm");
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@ const formattedTextStatus = (text: string) => {
return text?.replace(/-/g, " ").replace(/\b\w/g, char => char.toUpperCase());
};

const getTextForActionTable = (item: { type: string; status: string; request_removed: boolean }): string => {
if (item.type === "comment") {
const getTextForActionTable = (
item: { type: string; status: string; request_removed: boolean },
entity?: string
): string => {
if (item.type === "comment" && entity == "site-polygon") {
return "New Comment";
} else if (item.type === "status") {
} else if (item.type === "status" && entity == "site-polygon") {
return `New Status: ${formattedTextStatus(item.status)}`;
} else if (item.type === "change-request-updated") {
return "Change Request Updated";
} else if (item.request_removed) {
} else if (item.request_removed && entity == "site-polygon") {
return "Change Request Removed";
} else if (item.type === "reminder-sent") {
return "Reminder Sent";
} else {
} else if (item.type === "change-request") {
return "Change Requested";
} else {
return "-";
}
};

Expand All @@ -42,10 +47,30 @@ const AuditLogTable: FC<{
const menuOverflowContainerRef = useRef(null);
const route = useRouter();
const isAdmin = route.asPath.includes("admin");
const columnTitles = isAdmin
? ["Date", "User", "Action", "Comments", "Attachments", ""]
: ["Date", "User", "Action", "Comments", "Attachments"];
const gridColumnSize = isAdmin ? "grid-cols-[14%_20%_15%_27%_19%_5%]" : "grid-cols-[14%_20%_15%_30%_21%]";

const getColumnTitles = (entity: string, isAdmin: boolean) => {
if (entity === "site-polygon") {
return isAdmin
? ["Date", "User", "Action", "Comments", "Attachments", ""]
: ["Date", "User", "Action", "Comments", "Attachments"];
} else {
return isAdmin
? ["Date", "User", "Status", "Change Request", "Comments", "Attachments", ""]
: ["Date", "User", "Status", "Change Request", "Comments", "Attachments"];
}
};

const getGridColumnSize = (entity: string, isAdmin: boolean) => {
if (entity === "site-polygon") {
return isAdmin ? "grid-cols-[14%_20%_15%_27%_19%_5%]" : "grid-cols-[14%_20%_15%_30%_21%]";
} else {
return isAdmin ? "grid-cols-[14%_10%_10%_15%_27%_19%_5%]" : "grid-cols-[14%_10%_10%_15%_30%_21%]";
}
};

const columnTitles = getColumnTitles(auditData?.entity as string, isAdmin);
const gridColumnSize = getGridColumnSize(auditData?.entity as string, isAdmin);

const { openNotification } = useNotificationContext();
const t = useT();
const { mutate } = useDeleteV2ENTITYUUIDIDDelete({
Expand Down Expand Up @@ -87,8 +112,16 @@ const AuditLogTable: FC<{
<Text variant="text-12" className="border-b border-b-grey-750 py-2 pr-2">
{generateUserName(item.first_name, item.last_name)}
</Text>
<When condition={auditData?.entity !== "site-polygon"}>
<Text variant="text-12" className="border-b border-b-grey-750 py-2 pr-2">
{formattedTextStatus(item.status as string) ?? "-"}
</Text>
</When>
<Text variant="text-12" className="border-b border-b-grey-750 py-2 pr-2">
{getTextForActionTable(item as { type: string; status: string; request_removed: boolean })}
{getTextForActionTable(
item as { type: string; status: string; request_removed: boolean },
auditData?.entity
)}
</Text>
<Text variant="text-12" className="border-b border-b-grey-750 py-2">
{item.comment ?? "-"}
Expand Down
4 changes: 2 additions & 2 deletions src/components/extensive/WizardForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface WizardFormProps {
steps: FormStepSchema[];
defaultValues?: any;
onStepChange?: (values: any, step: FormStepSchema) => void;
onChange?: (values: any) => void;
onChange?: (values: any, isCloseAndSave?: boolean) => void;
onSubmit?: (values: any) => void;
onBackFirstStep: () => void;
onCloseForm?: () => void;
Expand Down Expand Up @@ -115,7 +115,7 @@ function WizardForm(props: WizardFormProps) {
};

const onClickSaveAndClose = () => {
props.onChange?.(formHook.getValues());
props.onChange?.(formHook.getValues(), true);
modal.openModal(
ModalId.SAVE_AND_CLOSE_MODAL,
<SaveAndCloseModal
Expand Down
8 changes: 6 additions & 2 deletions src/pages/entity/[entityName]/edit/[uuid]/EditEntityForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,14 @@ const EditEntityForm = ({ entityName, entityUUID, entity, formData }: EditEntity
errors={error}
onBackFirstStep={router.back}
onCloseForm={() => router.push("/home")}
onChange={data =>
onChange={(data, closeAndSave?: boolean) =>
updateEntity({
pathParams: { uuid: entityUUID, entity: entityName },
body: { answers: normalizedFormData(data, formSteps!) }
// @ts-ignore
body: {
answers: normalizedFormData(data, formSteps!),
...(closeAndSave ? { continue_later_action: true } : {})
}
})
}
formStatus={isSuccess ? "saved" : isUpdating ? "saving" : undefined}
Expand Down

0 comments on commit 9d0f6ba

Please sign in to comment.