IO-2893 Enhance disable of editing of tickets
Signed-off-by: Allan Carr <allan.carr@thinkimex.com>
This commit is contained in:
@@ -12,7 +12,7 @@ import { DateFormatter, DateTimeFormatter } from "../../utils/DateFormatter";
|
||||
import { onlyUnique } from "../../utils/arrayHelper";
|
||||
import dayjs from "../../utils/day";
|
||||
import { alphaSort, dateSort } from "../../utils/sorters";
|
||||
import RbacWrapper, { HasRbacAccess } from "../rbac-wrapper/rbac-wrapper.component";
|
||||
import { HasRbacAccess } from "../rbac-wrapper/rbac-wrapper.component";
|
||||
import TimeTicketEnterButton from "../time-ticket-enter-button/time-ticket-enter-button.component";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
@@ -52,6 +52,10 @@ export function TimeTicketList({
|
||||
splitKey: bodyshop.imexshopid
|
||||
});
|
||||
|
||||
const canEditCommittedTimeTickets = HasRbacAccess({ bodyshop, authLevel, action: "timetickets:editcommitted" });
|
||||
const canEditTimeTickets = HasRbacAccess({ bodyshop, authLevel, action: "timetickets:edit" });
|
||||
const canEditShiftTickets = HasRbacAccess({ bodyshop, authLevel, action: "timetickets:shiftedit" });
|
||||
|
||||
const totals = useMemo(() => {
|
||||
if (timetickets)
|
||||
return timetickets.reduce(
|
||||
@@ -65,6 +69,18 @@ export function TimeTicketList({
|
||||
return { productivehrs: 0, actualhrs: 0 };
|
||||
}, [timetickets]);
|
||||
|
||||
const isDisabled = (record) => {
|
||||
if (disabled === true || !record.id) return true;
|
||||
|
||||
const isShiftTicket = !record.ciecacode;
|
||||
const isCommitted = record.committed_at;
|
||||
if (isShiftTicket) {
|
||||
return !(canEditShiftTickets && (!isCommitted || canEditCommittedTimeTickets));
|
||||
}
|
||||
|
||||
return !(canEditTimeTickets && (!isCommitted || canEditCommittedTimeTickets));
|
||||
};
|
||||
|
||||
const columns = [
|
||||
...(Enhanced_Payroll.treatment === "on"
|
||||
? [
|
||||
@@ -241,59 +257,16 @@ export function TimeTicketList({
|
||||
</TimeTicketEnterButton>
|
||||
)}
|
||||
{!techConsole && (
|
||||
<RbacWrapper
|
||||
action="timetickets:edit"
|
||||
noauth={() => {
|
||||
return <div />;
|
||||
<TimeTicketEnterButton
|
||||
actions={{ refetch }}
|
||||
context={{
|
||||
id: record.id,
|
||||
timeticket: record
|
||||
}}
|
||||
disabled={isDisabled(record)}
|
||||
>
|
||||
<TimeTicketEnterButton
|
||||
actions={{ refetch }}
|
||||
context={{
|
||||
id: record.id,
|
||||
timeticket: record
|
||||
}}
|
||||
disabled={
|
||||
record.ciecacode
|
||||
? record.committed_at
|
||||
? HasRbacAccess({
|
||||
bodyshop,
|
||||
authLevel: authLevel,
|
||||
action: "timetickets:editcommitted"
|
||||
}) &&
|
||||
HasRbacAccess({
|
||||
bodyshop,
|
||||
authLevel: authLevel,
|
||||
action: "timetickets:edit"
|
||||
})
|
||||
: HasRbacAccess({
|
||||
bodyshop,
|
||||
authLevel: authLevel,
|
||||
action: "timetickets:edit"
|
||||
})
|
||||
: record.committed_at
|
||||
? HasRbacAccess({
|
||||
bodyshop,
|
||||
authLevel: authLevel,
|
||||
action: "timetickets:editcommitted"
|
||||
}) &&
|
||||
HasRbacAccess({
|
||||
bodyshop,
|
||||
authLevel: authLevel,
|
||||
action: "timetickets:shiftedit"
|
||||
})
|
||||
: HasRbacAccess({
|
||||
bodyshop,
|
||||
authLevel: authLevel,
|
||||
action: "timetickets:shiftedit"
|
||||
})
|
||||
? disabled
|
||||
: !record.jobid
|
||||
}
|
||||
>
|
||||
<EditFilled />
|
||||
</TimeTicketEnterButton>
|
||||
</RbacWrapper>
|
||||
<EditFilled />
|
||||
</TimeTicketEnterButton>
|
||||
)}
|
||||
</Space>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user