filter region
This commit is contained in:
parent
d5c2137927
commit
1c64beee61
|
@ -1,6 +1,6 @@
|
||||||
"use client"
|
"use client"
|
||||||
import { DocumentCurrencyDollarIcon, HomeIcon, UsersIcon } from "@heroicons/react/24/outline";
|
import { DocumentCurrencyDollarIcon, HomeIcon, UsersIcon } from "@heroicons/react/24/outline";
|
||||||
import { InputLabel, MenuItem, Select, TextField } from "@mui/material";
|
import { Autocomplete, InputLabel, MenuItem, Select, TextField } from "@mui/material";
|
||||||
import { DatePicker } from "@mui/x-date-pickers";
|
import { DatePicker } from "@mui/x-date-pickers";
|
||||||
import { BarChart2, CircleDollarSign, LogOut, RefreshCcw } from "lucide-react";
|
import { BarChart2, CircleDollarSign, LogOut, RefreshCcw } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
@ -13,6 +13,7 @@ import { Filter } from "@/services/types";
|
||||||
import { useAppDispatch, useAppSelector } from "@/lib/hooks";
|
import { useAppDispatch, useAppSelector } from "@/lib/hooks";
|
||||||
import { setFilter } from "@/lib/slice/filter";
|
import { setFilter } from "@/lib/slice/filter";
|
||||||
import { format } from "date-fns";
|
import { format } from "date-fns";
|
||||||
|
import { useGetFilterOptionsQuery } from "@/services/api";
|
||||||
|
|
||||||
|
|
||||||
export default function DashboardLayout({children}:{children: React.ReactNode}) {
|
export default function DashboardLayout({children}:{children: React.ReactNode}) {
|
||||||
|
@ -20,6 +21,7 @@ export default function DashboardLayout({children}:{children: React.ReactNode})
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const filter = useAppSelector((state) => state.filter.filter);
|
const filter = useAppSelector((state) => state.filter.filter);
|
||||||
|
const {data: filterOptions } = useGetFilterOptionsQuery(filter);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen">
|
<div className="flex min-h-screen">
|
||||||
|
@ -81,7 +83,7 @@ export default function DashboardLayout({children}:{children: React.ReactNode})
|
||||||
<div className="w-0.5 bg-amber-800 h-4"/>
|
<div className="w-0.5 bg-amber-800 h-4"/>
|
||||||
<span>CN</span>
|
<span>CN</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-4">
|
<div className="flex gap-4 ml-12">
|
||||||
<DatePicker label="Start Date" className="w-40"
|
<DatePicker label="Start Date" className="w-40"
|
||||||
slotProps={{
|
slotProps={{
|
||||||
textField: {
|
textField: {
|
||||||
|
@ -101,13 +103,14 @@ export default function DashboardLayout({children}:{children: React.ReactNode})
|
||||||
onChange={(date) => dispatch(setFilter({...filter, end_date: format(date ?? new Date(), "yyyy-MM-dd")}))}
|
onChange={(date) => dispatch(setFilter({...filter, end_date: format(date ?? new Date(), "yyyy-MM-dd")}))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex gap-4 w-80">
|
<div className="flex gap-4 w-full mx-24">
|
||||||
<TextField label="Company" size="small" select className="w-full">
|
<Autocomplete
|
||||||
<MenuItem value="0">Semua Perusahaan</MenuItem>
|
className="w-full"
|
||||||
<MenuItem value="1">PT. A</MenuItem>
|
options={filterOptions?.regions ?? []}
|
||||||
<MenuItem value="2">PT. B</MenuItem>
|
getOptionLabel={(option) => option.name}
|
||||||
<MenuItem value="3">PT. C</MenuItem>
|
renderInput={(params) => <TextField {...params} label="Region" size="small"/>}
|
||||||
</TextField>
|
onChange={(e, value) => dispatch(setFilter({...filter, organization_code: value?.codes ?? ""}))}
|
||||||
|
/>
|
||||||
<TextField label="Lokasi" size="small" select className="w-full">
|
<TextField label="Lokasi" size="small" select className="w-full">
|
||||||
<MenuItem value="0">Semua Lokasi</MenuItem>
|
<MenuItem value="0">Semua Lokasi</MenuItem>
|
||||||
<MenuItem value="1">Lokasi 1</MenuItem>
|
<MenuItem value="1">Lokasi 1</MenuItem>
|
||||||
|
|
|
@ -1,10 +1,18 @@
|
||||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
|
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
|
||||||
import { AttendanceRange, AttendanceSummary, EmployeeSummary, MonthlyAttendance, MonthlyEmployee, ResignationCategory, ResignationReason, ResignationType as ResignationType, ResignSummary } from './types'
|
import { AttendanceRange, AttendanceSummary, EmployeeSummary, FilterOptions, MonthlyAttendance, MonthlyEmployee, ResignationCategory, ResignationReason, ResignationType as ResignationType, ResignSummary } from './types'
|
||||||
import { Response , Filter} from './types'
|
import { Response , Filter} from './types'
|
||||||
|
|
||||||
export const api = createApi({
|
export const api = createApi({
|
||||||
baseQuery: fetchBaseQuery({ baseUrl: 'https://erp.julongindonesia.com:8443/api' }),
|
baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:8080' }),
|
||||||
endpoints: (builder) => ({
|
endpoints: (builder) => ({
|
||||||
|
getFilterOptions: builder.query<FilterOptions, Filter>({
|
||||||
|
query: (params) => ({ url: '/dashboard/filter-options', params }),
|
||||||
|
transformResponse: (response: Response) => {
|
||||||
|
if (response.status === "success") {
|
||||||
|
return response.data!;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
getEmployeeSummary: builder.query<EmployeeSummary[], Filter>({
|
getEmployeeSummary: builder.query<EmployeeSummary[], Filter>({
|
||||||
query: (params) => ({ url: '/dashboard/employee', params }),
|
query: (params) => ({ url: '/dashboard/employee', params }),
|
||||||
transformResponse: (response: Response) => {
|
transformResponse: (response: Response) => {
|
||||||
|
@ -80,6 +88,6 @@ export const api = createApi({
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const { useGetEmployeeSummaryQuery, useGetMonthlyEmployeeQuery, useGetMonthlyAttendanceQuery,
|
export const { useGetFilterOptionsQuery, useGetEmployeeSummaryQuery, useGetMonthlyEmployeeQuery, useGetMonthlyAttendanceQuery,
|
||||||
useGetOrganizationAttendanceQuery, useGetAttendanceRangeQuery, useGetResignSummaryQuery, useGetResignTypeQuery,
|
useGetOrganizationAttendanceQuery, useGetAttendanceRangeQuery, useGetResignSummaryQuery, useGetResignTypeQuery,
|
||||||
useGetResignCategoryQuery, useGetResignReasonQuery } = api
|
useGetResignCategoryQuery, useGetResignReasonQuery } = api
|
|
@ -19,6 +19,20 @@ export interface Filter{
|
||||||
job_name?: string;
|
job_name?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FilterOptions{
|
||||||
|
regions: {
|
||||||
|
name: string;
|
||||||
|
codes: string;
|
||||||
|
}[];
|
||||||
|
organizations: {
|
||||||
|
code: string;
|
||||||
|
name: string;
|
||||||
|
}[];
|
||||||
|
estates: {
|
||||||
|
name: string;
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
export type EmployeeSummary = {
|
export type EmployeeSummary = {
|
||||||
id: string;
|
id: string;
|
||||||
organization_code: string;
|
organization_code: string;
|
||||||
|
|
Loading…
Reference in New Issue