You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1.4 KiB

  1. import React from "react";
  2. import ResourceOvercomsumptionReportLoading from "./ResourceOverconsumptionReportLoading";
  3. import ResourceOverconsumptionReport from "./ResourceOverconsumptionReport";
  4. import { fetchTeam } from "@/app/api/team";
  5. import { fetchAllCustomers } from "@/app/api/customer";
  6. import { fetchAllSubsidiaries } from "@/app/api/subsidiary";
  7. import { getServerSession } from "next-auth";
  8. import { authOptions } from "@/config/authConfig";
  9. import { TEAM_LEAD } from "@/middleware";
  10. interface SubComponents {
  11. Loading: typeof ResourceOvercomsumptionReportLoading;
  12. }
  13. const ResourceOvercomsumptionReportWrapper: React.FC &
  14. SubComponents = async () => {
  15. const session: any = await getServerSession(authOptions);
  16. const teamId = session.staff?.team.id;
  17. const role = session.role;
  18. let needAll = true;
  19. let teams = await fetchTeam();
  20. const [customers, subsidiaries] = await Promise.all([
  21. fetchAllCustomers(),
  22. fetchAllSubsidiaries(),
  23. ]);
  24. if (role === TEAM_LEAD) {
  25. needAll = false;
  26. teams = teams.filter((team) => team.id === teamId);
  27. }
  28. return (
  29. <ResourceOverconsumptionReport
  30. team={teams}
  31. customer={customers}
  32. subsidiaries={subsidiaries}
  33. needAll={needAll}
  34. />
  35. );
  36. };
  37. ResourceOvercomsumptionReportWrapper.Loading =
  38. ResourceOvercomsumptionReportLoading;
  39. export default ResourceOvercomsumptionReportWrapper;