Compare commits

..

No commits in common. "f581b0e311e441e4d954a3ce11d688872c62aabc" and "e466fd27be48516c5445a62595e45d46c94911f8" have entirely different histories.

4 changed files with 51 additions and 74 deletions

View File

@ -10,10 +10,8 @@ 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( const selectedTenant = useSelector((store)=>store.globalVariables.currentTenant)
(store) => store.globalVariables.currentTenant const naviget = useNavigate()
);
const naviget = useNavigate();
const { const {
data: plans = [], data: plans = [],
isError, isError,
@ -28,13 +26,9 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
formState: { errors }, formState: { errors },
} = useFormContext(); } = useFormContext();
const { const {mutate:AddSubScription,isPending,error} = useAddSubscription(()=>{
mutate: AddSubScription, onNext()
isPending, } )
error,
} = useAddSubscription(() => {
onNext();
});
const handleSubscriptionSubmit = async () => { const handleSubscriptionSubmit = async () => {
const isValid = await trigger([ const isValid = await trigger([
"planId", "planId",
@ -48,8 +42,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)
} }
}; };
@ -115,24 +109,19 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
Features Features
</div> </div>
</div> </div>
{plan?.features && {Object.entries(plan.features.modules)
Object.entries(plan?.features?.modules || {}) .filter(([key]) => key !== "id")
.filter(([key]) => key !== "id") .map(([key, mod]) => (
.map(([key, mod]) => ( <div
<div key={key}
key={key} 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 ${ ></i>
mod.enabled <small className="ms-1">{mod.name}</small>
? "fa-circle-check text-success" </div>
: "fa-circle-xmark text-danger" ))}
}`}
></i>
<small className="ms-1">{mod.name}</small>
</div>
))}
</div> </div>
<button <button
@ -152,10 +141,7 @@ 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> <Label htmlFor="maxUsers" required> Team Size</Label>
{" "}
Team Size
</Label>
<input <input
type="number" type="number"
className="form-control form-control-sm" className="form-control form-control-sm"
@ -210,7 +196,7 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
type="button" type="button"
disabled={isPending} disabled={isPending}
> >
{isPending ? "Please Wait..." : "Submit"} {isPending ? "Please Wait...":"Submit"}
</button> </button>
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
import React, { useState,useCallback } from "react"; import React, { useState } 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";
@ -10,44 +10,30 @@ import { DateRangePicker1 } from "../common/DateRangePicker";
import moment from "moment"; 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 { handleSubmit, reset } = methods; const { data, isError, isLoading } = useIndustries();
const { data: industries = [], isLoading } = useIndustries(); const closePanel = () => {
const handleClosePanel = useCallback(() => {
document.querySelector(".offcanvas.show .btn-close")?.click(); document.querySelector(".offcanvas.show .btn-close")?.click();
}, []); };
const onSubmit = (formData) => {
const onSubmit = useCallback( onApply({
(formData) => { ...formData
onApply({ })
...formData, };
startDate: moment.utc(formData.startDate, "DD-MM-YYYY").toISOString(), const onClear = () => {
endDate: moment.utc(formData.endDate, "DD-MM-YYYY").toISOString(), reset(filterSchema);
}); setResetKey((prev) => prev + 1);
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>;
}
closePanel();
};
if (isLoading) return <div className="text-center">Loading...</div>;
return ( return (
<FormProvider {...methods}> <FormProvider {...method}>
<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">
@ -62,7 +48,7 @@ const [resetKey, setResetKey] = useState(0);
<SelectMultiple <SelectMultiple
name="industryIds" name="industryIds"
label="Industries" label="Industries"
options={industries} options={data}
labelKey="name" labelKey="name"
valueKey="id" valueKey="id"
/> />
@ -99,11 +85,10 @@ const [resetKey, setResetKey] = useState(0);
type="button" type="button"
className="btn btn-secondary btn-xs" className="btn btn-secondary btn-xs"
onClick={onClear} onClick={onClear}
> >
Clear Clear
</button> </button>
<button type="submit" className="btn btn-primary btn-xs" > <button type="submit" className="btn btn-primary btn-xs">
Apply Apply
</button> </button>
</div> </div>

View File

@ -45,10 +45,16 @@ 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: "frineds", name: "Friends" }, { val: "frined", name: "Friend" },
{ val: "advertisement", name: "Advertisement" }, { val: "advertisement", name: "Advertisement" },
{ val: "root tenant", name: "Root Tenant" }, { val: "root tenant", name: "Root Tenant" },
]; ];