Compare commits

...

2 Commits

Author SHA1 Message Date
f581b0e311 resolved filter issues 2025-08-12 14:53:48 +05:30
56b5633c51 handle error if features missing 2025-08-12 12:13:04 +05:30
4 changed files with 75 additions and 52 deletions

View File

@ -10,8 +10,10 @@ import { useNavigate } from "react-router-dom";
const SubScription = ({ onSubmitSubScription, onNext }) => { const SubScription = ({ onSubmitSubScription, onNext }) => {
const [frequency, setFrequency] = useState(2); const [frequency, setFrequency] = useState(2);
const [selectedPlanId, setSelectedPlanId] = useState(null); const [selectedPlanId, setSelectedPlanId] = useState(null);
const selectedTenant = useSelector((store)=>store.globalVariables.currentTenant) const selectedTenant = useSelector(
const naviget = useNavigate() (store) => store.globalVariables.currentTenant
);
const naviget = useNavigate();
const { const {
data: plans = [], data: plans = [],
isError, isError,
@ -26,9 +28,13 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
formState: { errors }, formState: { errors },
} = useFormContext(); } = useFormContext();
const {mutate:AddSubScription,isPending,error} = useAddSubscription(()=>{ const {
onNext() mutate: AddSubScription,
} ) isPending,
error,
} = useAddSubscription(() => {
onNext();
});
const handleSubscriptionSubmit = async () => { const handleSubscriptionSubmit = async () => {
const isValid = await trigger([ const isValid = await trigger([
"planId", "planId",
@ -42,8 +48,8 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
if (isValid) { if (isValid) {
const payload = getValues(); const payload = getValues();
// onSubmitSubScription(payload); // onSubmitSubScription(payload);
const subscriptionPayload = {...payload,tenantId:selectedTenant.id} const subscriptionPayload = { ...payload, tenantId: selectedTenant.id };
AddSubScription(subscriptionPayload) AddSubScription(subscriptionPayload);
} }
}; };
@ -109,7 +115,8 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
Features Features
</div> </div>
</div> </div>
{Object.entries(plan.features.modules) {plan?.features &&
Object.entries(plan?.features?.modules || {})
.filter(([key]) => key !== "id") .filter(([key]) => key !== "id")
.map(([key, mod]) => ( .map(([key, mod]) => (
<div <div
@ -117,7 +124,11 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
className="mb-2 d-flex align-items-center" className="mb-2 d-flex align-items-center"
> >
<i <i
className={`fa-regular ${mod.enabled ? "fa-circle-check text-success" : "fa-circle-xmark text-danger"} `} className={`fa-regular ${
mod.enabled
? "fa-circle-check text-success"
: "fa-circle-xmark text-danger"
}`}
></i> ></i>
<small className="ms-1">{mod.name}</small> <small className="ms-1">{mod.name}</small>
</div> </div>
@ -141,7 +152,10 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
{/* Form Inputs */} {/* Form Inputs */}
<div className="row g-2 mt-3"> <div className="row g-2 mt-3">
<div className="col-sm-4"> <div className="col-sm-4">
<Label htmlFor="maxUsers" required> Team Size</Label> <Label htmlFor="maxUsers" required>
{" "}
Team Size
</Label>
<input <input
type="number" type="number"
className="form-control form-control-sm" className="form-control form-control-sm"

View File

@ -1,5 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
import React, { useState } from "react"; import React, { useState,useCallback } from "react";
import { FormProvider, useForm, useFormContext } from "react-hook-form"; import { FormProvider, useForm, useFormContext } from "react-hook-form";
import { defaultFilterValues, filterSchema } from "./TenantSchema"; import { defaultFilterValues, filterSchema } from "./TenantSchema";
import Label from "../common/Label"; import Label from "../common/Label";
@ -11,29 +11,43 @@ import moment from "moment";
const TenantFilterPanel = ({onApply}) => { const TenantFilterPanel = ({onApply}) => {
const [resetKey, setResetKey] = useState(0); const [resetKey, setResetKey] = useState(0);
const method = useForm({
const methods = useForm({
resolver: zodResolver(filterSchema), resolver: zodResolver(filterSchema),
defaultValues: defaultFilterValues, defaultValues: defaultFilterValues,
}); });
const { control, register, handleSubmit, reset, watch } = method;
const { data, isError, isLoading } = useIndustries();
const closePanel = () => {
document.querySelector(".offcanvas.show .btn-close")?.click();
};
const onSubmit = (formData) => {
onApply({
...formData
})
};
const onClear = () => {
reset(filterSchema);
setResetKey((prev) => prev + 1);
closePanel(); const { handleSubmit, reset } = methods;
}; const { data: industries = [], isLoading } = useIndustries();
if (isLoading) return <div className="text-center">Loading...</div>;
const handleClosePanel = useCallback(() => {
document.querySelector(".offcanvas.show .btn-close")?.click();
}, []);
const onSubmit = useCallback(
(formData) => {
onApply({
...formData,
startDate: moment.utc(formData.startDate, "DD-MM-YYYY").toISOString(),
endDate: moment.utc(formData.endDate, "DD-MM-YYYY").toISOString(),
});
handleClosePanel();
},
[onApply, handleClosePanel]
);
const onClear = useCallback(() => {
reset(defaultFilterValues);
setResetKey((prev) => prev + 1); // triggers DateRangePicker reset
onApply(defaultFilterValues);
}, [onApply, reset]);
if (isLoading) {
return <div className="text-center">Loading...</div>;
}
return ( return (
<FormProvider {...method}> <FormProvider {...methods}>
<form onSubmit={handleSubmit(onSubmit)}> <form onSubmit={handleSubmit(onSubmit)}>
<div className="text-start mb-1"> <div className="text-start mb-1">
<div className="text-start my-2"> <div className="text-start my-2">
@ -48,7 +62,7 @@ const TenantFilterPanel = ({onApply}) => {
<SelectMultiple <SelectMultiple
name="industryIds" name="industryIds"
label="Industries" label="Industries"
options={data} options={industries}
labelKey="name" labelKey="name"
valueKey="id" valueKey="id"
/> />
@ -85,6 +99,7 @@ const TenantFilterPanel = ({onApply}) => {
type="button" type="button"
className="btn btn-secondary btn-xs" className="btn btn-secondary btn-xs"
onClick={onClear} onClick={onClear}
> >
Clear Clear
</button> </button>

View File

@ -45,16 +45,10 @@ const TenantPage = () => {
}); });
const { reset } = methods; const { reset } = methods;
const clearFilter = () => {
setFilter(defaultFilter);
reset();
};
useEffect(() => { useEffect(() => {
setShowTrigger(true); setShowTrigger(true);
setOffcanvasContent("Tenant Filters", <TenantFilterPanel onApply={setFilter} setOffcanvasContent("Tenant Filters", <TenantFilterPanel onApply={setFilter}
/>);
clearFilter={clearFilter}/>);
return () => { return () => {
setShowTrigger(false); setShowTrigger(false);
setOffcanvasContent("", null); setOffcanvasContent("", null);

View File

@ -78,7 +78,7 @@ export const CONSTANT_TEXT = {
} }
export const reference = [ export const reference = [
{ val: "google", name: "Google" }, { val: "google", name: "Google" },
{ val: "frined", name: "Friend" }, { val: "frineds", name: "Friends" },
{ val: "advertisement", name: "Advertisement" }, { val: "advertisement", name: "Advertisement" },
{ val: "root tenant", name: "Root Tenant" }, { val: "root tenant", name: "Root Tenant" },
]; ];