In ExpensePanel add new Toggle button.
This commit is contained in:
parent
4683eff749
commit
d87dae4799
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState,useMemo } from "react";
|
import React, { useEffect, useState, useMemo } from "react";
|
||||||
import { FormProvider, useForm, Controller } from "react-hook-form";
|
import { FormProvider, useForm, Controller } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { defaultFilter, SearchSchema } from "./ExpenseSchema";
|
import { defaultFilter, SearchSchema } from "./ExpenseSchema";
|
||||||
@ -17,7 +17,7 @@ import { useLocation } from "react-router-dom";
|
|||||||
|
|
||||||
const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
||||||
const selectedProjectId = useSelector((store) => store.localVariables.projectId);
|
const selectedProjectId = useSelector((store) => store.localVariables.projectId);
|
||||||
const { data, isLoading,isError,error,isFetching , isFetched} = useExpenseFilter();
|
const { data, isLoading, isError, error, isFetching, isFetched } = useExpenseFilter();
|
||||||
|
|
||||||
const groupByList = useMemo(() => {
|
const groupByList = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
@ -27,11 +27,10 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
|||||||
{ id: "project", name: "Project" },
|
{ id: "project", name: "Project" },
|
||||||
{ id: "paymentMode", name: "Payment Mode" },
|
{ id: "paymentMode", name: "Payment Mode" },
|
||||||
{ id: "expensesType", name: "Expense Type" },
|
{ id: "expensesType", name: "Expense Type" },
|
||||||
{ id: "createdAt", name: "Submitted Date" }
|
{ id: "createdAt", name: "Submitted Date" }
|
||||||
].sort((a, b) => a.name.localeCompare(b.name));
|
].sort((a, b) => a.name.localeCompare(b.name));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
const [selectedGroup, setSelectedGroup] = useState(groupByList[0]);
|
const [selectedGroup, setSelectedGroup] = useState(groupByList[0]);
|
||||||
const [resetKey, setResetKey] = useState(0);
|
const [resetKey, setResetKey] = useState(0);
|
||||||
|
|
||||||
@ -40,7 +39,7 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
|||||||
defaultValues: defaultFilter,
|
defaultValues: defaultFilter,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { control, register, handleSubmit, reset, watch } = methods;
|
const { control, handleSubmit, reset, setValue, watch } = methods;
|
||||||
const isTransactionDate = watch("isTransactionDate");
|
const isTransactionDate = watch("isTransactionDate");
|
||||||
|
|
||||||
const closePanel = () => {
|
const closePanel = () => {
|
||||||
@ -78,7 +77,7 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
|||||||
}, [location]);
|
}, [location]);
|
||||||
|
|
||||||
if (isLoading || isFetching) return <ExpenseFilterSkeleton />;
|
if (isLoading || isFetching) return <ExpenseFilterSkeleton />;
|
||||||
if(isError && isFetched) return <div>Something went wrong Here- {error.message} </div>
|
if (isError && isFetched) return <div>Something went wrong Here- {error.message} </div>
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
@ -86,18 +85,29 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
|||||||
<form onSubmit={handleSubmit(onSubmit)} className="p-2 text-start">
|
<form onSubmit={handleSubmit(onSubmit)} className="p-2 text-start">
|
||||||
<div className="mb-3 w-100">
|
<div className="mb-3 w-100">
|
||||||
<div className="d-flex align-items-center mb-2">
|
<div className="d-flex align-items-center mb-2">
|
||||||
<label className="form-label me-2">Choose Date:</label>
|
<label className="form-label me-2">Sort By:</label>
|
||||||
<div className="form-check form-switch m-0">
|
<div className="d-inline-flex border rounded-pill mb-1 overflow-hidden shadow-none">
|
||||||
<input
|
<button
|
||||||
className="form-check-input"
|
type="button"
|
||||||
type="checkbox"
|
className={`btn px-2 py-1 rounded-0 text-tiny ${isTransactionDate
|
||||||
id="switchOption1"
|
? "active btn-secondary text-white"
|
||||||
{...register("isTransactionDate")}
|
: ""
|
||||||
/>
|
}`}
|
||||||
|
onClick={() => setValue("isTransactionDate", true)}
|
||||||
|
>
|
||||||
|
Transaction
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`btn px-2 py-1 rounded-0 text-tiny ${!isTransactionDate
|
||||||
|
? "active btn-secondary text-white"
|
||||||
|
: ""
|
||||||
|
}`}
|
||||||
|
onClick={() => setValue("isTransactionDate", false)}
|
||||||
|
>
|
||||||
|
Submitted
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<label className="form-label mb-0 ms-2">
|
|
||||||
{isTransactionDate ? "Submitted": "Transaction" }
|
|
||||||
</label>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DateRangePicker1
|
<DateRangePicker1
|
||||||
@ -169,7 +179,7 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-2 text-start ">
|
<div className="mb-2 text-start ">
|
||||||
<label htmlFor="groupBySelect" className="form-label">Group By :</label>
|
<label htmlFor="groupBySelect" className="form-label">Group By :</label>
|
||||||
<select
|
<select
|
||||||
id="groupBySelect"
|
id="groupBySelect"
|
||||||
className="form-select form-select-sm"
|
className="form-select form-select-sm"
|
||||||
@ -198,7 +208,7 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => {
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</FormProvider>
|
</FormProvider>
|
||||||
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user