Updated the expiry date to be based on the expiry date
This commit is contained in:
@@ -30,9 +30,12 @@ import { toFixedNumber } from "@/utils/number";
|
||||
import { CSVLink } from "react-csv";
|
||||
import { Tab } from "@headlessui/react";
|
||||
import { useListSearch } from "@/hooks/useListSearch";
|
||||
import { checkAccess, getTypesOfUser } from "@/utils/permissions";
|
||||
import { checkAccess, findAllowedEntities, getTypesOfUser } from "@/utils/permissions";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { redirect } from "@/utils";
|
||||
import { mapBy, redirect, serialize } from "@/utils";
|
||||
import { getEntities, getEntitiesWithRoles } from "@/utils/entities.be";
|
||||
import { isAdmin } from "@/utils/users";
|
||||
import { Entity, EntityWithRoles } from "@/interfaces/entity";
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
||||
const user = await requestUser(req, res)
|
||||
@@ -42,8 +45,13 @@ export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
||||
return redirect("/")
|
||||
}
|
||||
|
||||
const entityIDs = mapBy(user.entities, 'id')
|
||||
const entities = await getEntitiesWithRoles(isAdmin(user) ? undefined : entityIDs)
|
||||
|
||||
const allowedEntities = findAllowedEntities(user, entities, "view_payment_record")
|
||||
|
||||
return {
|
||||
props: { user },
|
||||
props: serialize({ user, entities: allowedEntities }),
|
||||
};
|
||||
}, sessionOptions);
|
||||
|
||||
@@ -273,7 +281,13 @@ interface PaypalPaymentWithUserData extends PaypalPayment {
|
||||
}
|
||||
|
||||
const paypalFilterRows = [["email"], ["name"], ["orderId"], ["value"]];
|
||||
export default function PaymentRecord() {
|
||||
|
||||
interface Props {
|
||||
user: User
|
||||
entities: EntityWithRoles[]
|
||||
}
|
||||
|
||||
export default function PaymentRecord({ user, entities }: Props) {
|
||||
const [selectedCorporateUser, setSelectedCorporateUser] = useState<User>();
|
||||
const [selectedAgentUser, setSelectedAgentUser] = useState<User>();
|
||||
const [isCreatingPayment, setIsCreatingPayment] = useState(false);
|
||||
@@ -281,9 +295,9 @@ export default function PaymentRecord() {
|
||||
const [displayPayments, setDisplayPayments] = useState<Payment[]>([]);
|
||||
|
||||
const [corporate, setCorporate] = useState<User>();
|
||||
const [entity, setEntity] = useState<Entity>();
|
||||
const [agent, setAgent] = useState<User>();
|
||||
|
||||
const { user } = useUser({ redirectTo: "/login" });
|
||||
const { users, reload: reloadUsers } = useUsers();
|
||||
const { payments: originalPayments, reload: reloadPayment } = usePayments();
|
||||
const { payments: paypalPayments, reload: reloadPaypalPayment } = usePaypalPayments();
|
||||
@@ -341,17 +355,17 @@ export default function PaymentRecord() {
|
||||
|
||||
useEffect(() => {
|
||||
setFilters((prev) => [
|
||||
...prev.filter((x) => x.id !== "corporate-filter"),
|
||||
...(!corporate
|
||||
...prev.filter((x) => x.id !== "entity-filter"),
|
||||
...(!entity
|
||||
? []
|
||||
: [
|
||||
{
|
||||
id: "corporate-filter",
|
||||
filter: (p: Payment) => p.corporate === corporate.id,
|
||||
id: "entity-filter",
|
||||
filter: (p: Payment) => p.entity === entity.id,
|
||||
},
|
||||
]),
|
||||
]);
|
||||
}, [corporate]);
|
||||
}, [entity]);
|
||||
|
||||
useEffect(() => {
|
||||
setFilters((prev) => [
|
||||
@@ -675,7 +689,7 @@ export default function PaymentRecord() {
|
||||
<Checkbox
|
||||
isChecked={value}
|
||||
onChange={(e) => {
|
||||
if (user?.type === agent || user?.type === "corporate" || value) return null;
|
||||
if (user?.type === "agent" || user?.type === "corporate" || value) return null;
|
||||
if (!info.row.original.commissionTransfer || !info.row.original.corporateTransfer)
|
||||
return alert("All files need to be uploaded to consider it paid!");
|
||||
if (!confirm(`Are you sure you want to consider this payment paid?`)) return null;
|
||||
|
||||
Reference in New Issue
Block a user