Procházet zdrojové kódy

Use grade and position from API for staff

tags/Baseline_30082024_FRONTEND_UAT
Wayne před 1 rokem
rodič
revize
cb49386ca7
6 změnil soubory, kde provedl 26 přidání a 29 odebrání
  1. +2
    -0
      src/app/(main)/projects/create/page.tsx
  2. +10
    -0
      src/app/api/grades/index.ts
  3. +9
    -9
      src/app/api/positions/index.ts
  4. +0
    -2
      src/components/CreateProject/CreateProject.tsx
  5. +4
    -8
      src/components/CreateProject/CreateProjectWrapper.tsx
  6. +1
    -10
      src/components/CreateProject/StaffAllocation.tsx

+ 2
- 0
src/app/(main)/projects/create/page.tsx Zobrazit soubor

@@ -1,4 +1,5 @@
import { fetchAllCustomers, fetchAllSubsidiaries } from "@/app/api/customer"; import { fetchAllCustomers, fetchAllSubsidiaries } from "@/app/api/customer";
import { fetchGrades } from "@/app/api/grades";
import { import {
fetchProjectBuildingTypes, fetchProjectBuildingTypes,
fetchProjectCategories, fetchProjectCategories,
@@ -34,6 +35,7 @@ const Projects: React.FC = async () => {
fetchProjectWorkNatures(); fetchProjectWorkNatures();
fetchAllCustomers(); fetchAllCustomers();
fetchAllSubsidiaries(); fetchAllSubsidiaries();
fetchGrades();
preloadTeamLeads(); preloadTeamLeads();
preloadStaff(); preloadStaff();




+ 10
- 0
src/app/api/grades/index.ts Zobrazit soubor

@@ -1,5 +1,15 @@
import { serverFetchJson } from "@/app/utils/fetchUtil";
import { BASE_API_URL } from "@/config/api";
import { cache } from "react";

export interface Grade { export interface Grade {
name: string; name: string;
id: number; id: number;
code: string; code: string;
} }

export const fetchGrades = cache(async () => {
return serverFetchJson<Grade[]>(`${BASE_API_URL}/grades`, {
next: { tags: ["grades"] },
});
});

+ 9
- 9
src/app/api/positions/index.ts Zobrazit soubor

@@ -4,18 +4,18 @@ import { cache } from "react";
import "server-only"; import "server-only";


export interface PositionResult { export interface PositionResult {
id: number;
code: string;
name: string;
description: string;
id: number;
code: string;
name: string;
description: string;
} }


export const preloadPositions = () => { export const preloadPositions = () => {
fetchPositions();
fetchPositions();
}; };


export const fetchPositions = cache(async () => { export const fetchPositions = cache(async () => {
return serverFetchJson<PositionResult[]>(`${BASE_API_URL}/positions`, {
next: { tags: ["positions"] },
});
});
return serverFetchJson<PositionResult[]>(`${BASE_API_URL}/positions`, {
next: { tags: ["positions"] },
});
});

+ 0
- 2
src/components/CreateProject/CreateProject.tsx Zobrazit soubor

@@ -51,8 +51,6 @@ export interface Props {
buildingTypes: BuildingType[]; buildingTypes: BuildingType[];
workNatures: WorkNature[]; workNatures: WorkNature[];
allStaffs: StaffResult[]; allStaffs: StaffResult[];

// Mocked
grades: Grade[]; grades: Grade[];
} }




+ 4
- 8
src/components/CreateProject/CreateProjectWrapper.tsx Zobrazit soubor

@@ -11,6 +11,7 @@ import {
} from "@/app/api/projects"; } from "@/app/api/projects";
import { fetchStaff, fetchTeamLeads } from "@/app/api/staff"; import { fetchStaff, fetchTeamLeads } from "@/app/api/staff";
import { fetchAllCustomers, fetchAllSubsidiaries } from "@/app/api/customer"; import { fetchAllCustomers, fetchAllSubsidiaries } from "@/app/api/customer";
import { fetchGrades } from "@/app/api/grades";


const CreateProjectWrapper: React.FC = async () => { const CreateProjectWrapper: React.FC = async () => {
const [ const [
@@ -27,6 +28,7 @@ const CreateProjectWrapper: React.FC = async () => {
buildingTypes, buildingTypes,
workNatures, workNatures,
allStaffs, allStaffs,
grades,
] = await Promise.all([ ] = await Promise.all([
fetchAllTasks(), fetchAllTasks(),
fetchTaskTemplates(), fetchTaskTemplates(),
@@ -41,6 +43,7 @@ const CreateProjectWrapper: React.FC = async () => {
fetchProjectBuildingTypes(), fetchProjectBuildingTypes(),
fetchProjectWorkNatures(), fetchProjectWorkNatures(),
fetchStaff(), fetchStaff(),
fetchGrades(),
]); ]);


return ( return (
@@ -58,14 +61,7 @@ const CreateProjectWrapper: React.FC = async () => {
buildingTypes={buildingTypes} buildingTypes={buildingTypes}
workNatures={workNatures} workNatures={workNatures}
allStaffs={allStaffs} allStaffs={allStaffs}
// Mocks
grades={[
{ name: "Grade 1", id: 1, code: "1" },
{ name: "Grade 2", id: 2, code: "2" },
{ name: "Grade 3", id: 3, code: "3" },
{ name: "Grade 4", id: 4, code: "4" },
{ name: "Grade 5", id: 5, code: "5" },
]}
grades={grades}
/> />
); );
}; };


+ 1
- 10
src/components/CreateProject/StaffAllocation.tsx Zobrazit soubor

@@ -54,7 +54,7 @@ export interface Props {
} }


const StaffAllocation: React.FC<Props> = ({ const StaffAllocation: React.FC<Props> = ({
allStaffs: dataStaffs,
allStaffs,
allTasks, allTasks,
isActive, isActive,
defaultManhourBreakdownByGrade, defaultManhourBreakdownByGrade,
@@ -63,15 +63,6 @@ const StaffAllocation: React.FC<Props> = ({
const { t } = useTranslation(); const { t } = useTranslation();
const { setValue, getValues, watch } = useFormContext<CreateProjectInputs>(); const { setValue, getValues, watch } = useFormContext<CreateProjectInputs>();


// TODO: remove this when grade and positions are done
const allStaffs = useMemo<StaffResult[]>(() => {
return dataStaffs.map((staff, index) => ({
...staff,
grade: grades[index % grades.length].name,
currentPosition: `Mock Postion ${index}`,
}));
}, [dataStaffs, grades]);

const [filteredStaff, setFilteredStaff] = React.useState( const [filteredStaff, setFilteredStaff] = React.useState(
allStaffs.sort(staffComparator), allStaffs.sort(staffComparator),
); );


Načítá se…
Zrušit
Uložit