max employees

master
alex 2024-02-11 11:33:53 +01:00
parent c9dde71aab
commit 6d3e41bbbb
4 changed files with 31 additions and 17 deletions

View File

@ -140,7 +140,11 @@ export function App() {
> >
<UserProfileProvider> <UserProfileProvider>
<UsersProvider> <UsersProvider>
<AppProvider> <AppProvider
options={{
paymentPlan: appUserData.user.payment_plan,
}}
>
<StoresProvider options={{ stores: appUserData.stores }}> <StoresProvider options={{ stores: appUserData.stores }}>
<DashboardLayout <DashboardLayout
userSession={userSession} userSession={userSession}

View File

@ -1,31 +1,22 @@
import { createContext, useContext, useEffect, useRef, useState } from "react"; import { createContext, useContext, useState } from "react";
import { myFetch, myFetchContentType } from "../utils";
const preview = { const preview = {
userId: "", paymentPlan: "",
userPermissions: [], setPaymentPlan: () => {},
users: [],
}; };
const AppContext = createContext(preview); const AppContext = createContext(preview);
export const useAppContext = () => useContext(AppContext); export const useAppContext = () => useContext(AppContext);
export function AppProvider({ children }) { export function AppProvider({ children, options }) {
const userId = useRef(""); // used for some conditions in webSocket message handler const [paymentPlan, setPaymentPlan] = useState(options.paymentPlan);
const [userPermissions, setUserPermissions] = useState([]);
// used for avatars and the tooltip for the avatar
const [users, setUsers] = useState([]); // { Id, Username, Avatar}
return ( return (
<AppContext.Provider <AppContext.Provider
value={{ value={{
userId, paymentPlan,
userPermissions, setPaymentPlan,
setUserPermissions,
users,
setUsers,
}} }}
> >
{children} {children}

View File

@ -17,6 +17,7 @@ import {
myFetch, myFetch,
EncodeStringToBase64, EncodeStringToBase64,
showInputsInvalidNotification, showInputsInvalidNotification,
Constants,
} from "../../../utils"; } from "../../../utils";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import MyTable from "../../../Components/MyTable"; import MyTable from "../../../Components/MyTable";
@ -29,6 +30,7 @@ import {
} from "../../../Components/MyFormInputs"; } from "../../../Components/MyFormInputs";
import { Link, useParams } from "react-router-dom"; import { Link, useParams } from "react-router-dom";
import CountUp from "react-countup"; import CountUp from "react-countup";
import { useAppContext } from "../../../Contexts/AppContext";
const { useBreakpoint } = Grid; const { useBreakpoint } = Grid;
@ -36,6 +38,7 @@ export default function StoreEmployees() {
const { t } = useTranslation(); const { t } = useTranslation();
const [notificationApi, notificationContextHolder] = const [notificationApi, notificationContextHolder] =
notification.useNotification(); notification.useNotification();
const appContext = useAppContext();
const screenBreakpoint = useBreakpoint(); const screenBreakpoint = useBreakpoint();
const { storeId } = useParams(); const { storeId } = useParams();
@ -178,6 +181,10 @@ export default function StoreEmployees() {
modalOptions={addEditEmployeeModalOptions} modalOptions={addEditEmployeeModalOptions}
setModalOptions={setAddEditEmployeeModalOptions} setModalOptions={setAddEditEmployeeModalOptions}
fetchEmployees={fetchEmployees} fetchEmployees={fetchEmployees}
disabled={
Constants.PAYMENT_PLAN[appContext.paymentPlan].maxEmployees <=
requestData.employees.length
}
/> />
</div> </div>
@ -197,6 +204,7 @@ function ModalAddEditEmployee({
modalOptions, modalOptions,
setModalOptions, setModalOptions,
fetchEmployees, fetchEmployees,
disabled,
}) { }) {
const { t, i18n } = useTranslation(); const { t, i18n } = useTranslation();
const [notificationApi, notificationContextHolder] = const [notificationApi, notificationContextHolder] =
@ -257,6 +265,7 @@ function ModalAddEditEmployee({
onClick={() => onClick={() =>
setModalOptions({ ...modalOptions, mode: "add", isOpen: true }) setModalOptions({ ...modalOptions, mode: "add", isOpen: true })
} }
disabled={disabled}
> >
{t("employees.addEmployee")} {t("employees.addEmployee")}
</Button> </Button>

View File

@ -102,6 +102,16 @@ export const Constants = {
PENDING_EMAIL_VERIFICATION: 4, PENDING_EMAIL_VERIFICATION: 4,
}, },
SUPPORT_EMAIL: process.env.REACT_APP_SUPPORT_EMAIL, SUPPORT_EMAIL: process.env.REACT_APP_SUPPORT_EMAIL,
PAYMENT_PLAN: [
{
id: 0, // free
maxEmployees: 5,
},
{
id: 1, // basic
maxEmployees: 15,
},
],
}; };
export function isEmailValid(email) { export function isEmailValid(email) {