Skip to content

Commit

Permalink
Advance the functionality of multiple modular policies in the legal m…
Browse files Browse the repository at this point in the history
…odule

Custom services menu to Mario and Julian for the risk events module
Fix the issue with the payslips of everyone in the MyPayslips module with the users with Payslips permissions
  • Loading branch information
S-e-b-a-s committed Apr 18, 2024
1 parent a4ec8e9 commit a3e2b06
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 37 deletions.
8 changes: 5 additions & 3 deletions src/components/common/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ const Navbar = () => {
<CustomNavLink to="/logged/blog">Blog</CustomNavLink>
<CustomNavLink to="/logged/sgc">Gestión Documental</CustomNavLink>
<CustomNavLink to="/logged/vacancies">Vacantes</CustomNavLink>
{servicesPermission ? (
{cedula === "19438555" || cedula === "1032495391" ? (
<CustomNavLink to="/logged/risk-events">Eventos de Riesgo</CustomNavLink>
) : servicesPermission ? (
<Button
id="button-utils"
endIcon={anchorElUtils ? <KeyboardArrowUpIcon /> : <KeyboardArrowDownIcon />}
Expand Down Expand Up @@ -466,13 +468,13 @@ const Navbar = () => {
transformOrigin={{ horizontal: "right", vertical: "top" }}
anchorOrigin={{ horizontal: "right", vertical: "bottom" }}
>
<MenuItem onClick={handleOpenAccountDialog}>
{/* <MenuItem onClick={handleOpenAccountDialog}>
<ListItemIcon>
<Avatar />
</ListItemIcon>
<ListItemText primary="Mi Cuenta" />
</MenuItem>
<Divider />
<Divider /> */}
{isAdvisor ? (
<MenuItem onClick={handleOpenDialog}>
<ListItemIcon>
Expand Down
3 changes: 1 addition & 2 deletions src/components/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import SnackbarAlert from "../common/SnackBarAlert";
import { Typography, Box, Container, useMediaQuery, Card } from "@mui/material";

// Media
import vacanciesCarousel from "../../images/home-carousel/vacancies-1280-720.png";
import realBenefit2 from "../../images/benefits/benefit-1.png";
import video from "../../videos/futbol.mp4";
import cake from "../../images/birthdays/cake.png";
Expand All @@ -24,7 +23,7 @@ import water2 from "../../images/home-carousel/water-2.png";

const benefits = [{ image: realBenefit2, title: "Beneficio 2" }];

const homeImages = [{ image: water2 }, { image: water }, { image: prosecutor }, { image: ceroDiscrimination }, { image: vacanciesCarousel }];
const homeImages = [{ image: water2 }, { image: water }, { image: prosecutor }, { image: ceroDiscrimination }];

const Home = () => {
const [openSnack, setOpenSnack] = useState(false);
Expand Down
70 changes: 41 additions & 29 deletions src/components/pages/Legal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import ModeEditIcon from "@mui/icons-material/ModeEdit";
import DeleteIcon from "@mui/icons-material/Delete";
import SaveIcon from "@mui/icons-material/Save";
import AddIcon from "@mui/icons-material/Add";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";

const validationSchema = Yup.object().shape({
name: Yup.string().required("Campo requerido"),
Expand Down Expand Up @@ -337,7 +338,7 @@ export const Legal = () => {
if (!response.ok) {
throw new Error(data.detail);
} else if (response.status === 200) {
handleCloseDialogEdit();
handleCloseDialogEdit();
getPolicies();
showSnack("success", "Se ha actualizado el registro correctamente.");
}
Expand All @@ -347,7 +348,7 @@ export const Legal = () => {
}
};

const handleAddPolicies = (inputName, i, policyType, inputLabel) => {
const handleAddPolicies = (inputName, i, policyType, inputLabel, updateValidationSchema) => {
inputName = inputName.split("end")[0]; // Remove the index from the input name
inputLabel = inputLabel.split("Fin ")[1]; // Remove the index from the input label

Expand Down Expand Up @@ -379,35 +380,25 @@ export const Legal = () => {
];

// Add the new inputs to the state inputs object in the correct position
if (policyType === "civilResponsibilityPolicy") {
setInputs({ ...inputs, civilResponsibilityPolicy: [...inputs.civilResponsibilityPolicy, ...newInputs] });
} else if (policyType === "compliancePolicy") {
setInputs({ ...inputs, compliancePolicy: [...inputs.compliancePolicy, ...newInputs] });
} else {
setInputs({ ...inputs, insurancePolicy: [...inputs.insurancePolicy, ...newInputs] });
}
setInputs({ ...inputs, [policyType]: [...inputs[policyType], ...newInputs] });

const updatedInitialValues = {
...newInitialValues,
setNewInitialValues((currentValues) => ({
...currentValues,
[`${inputName}_${i}`]: "",
[`${inputName}number_${i}`]: "",
[`${inputName}start_date_${i}`]: "",
[`${inputName}end_date_${i}`]: "",
};

console.log(updatedInitialValues);
setNewInitialValues(updatedInitialValues);
// Add the new inputs to the newInitialValues object

// Add the new inputs to the newValidationSchema object
const updatedValidationSchema = newValidationSchema.shape({
...newValidationSchema.fields,
[`${inputName}_${i}`]: Yup.string().required("Campo requerido"),
[`${inputName}number_${i}`]: Yup.string().required("Campo requerido"),
[`${inputName}start_date_${i}`]: Yup.string().required("Campo requerido"),
[`${inputName}end_date_${i}`]: Yup.string().required("Campo requerido"),
});
setNewValidationSchema(updatedValidationSchema);
}));

updateValidationSchema((currentSchema) =>
currentSchema.shape({
...currentSchema.fields,
[`${inputName}_${i}`]: Yup.string().required("Campo requerido"),
[`${inputName}number_${i}`]: Yup.string().required("Campo requerido"),
[`${inputName}start_date_${i}`]: Yup.string().required("Campo requerido"),
[`${inputName}end_date_${i}`]: Yup.string().required("Campo requerido"),
})
);
};

const FormikTextField = ({ label, type, options, multiline, rows, ...props }) => {
Expand Down Expand Up @@ -558,14 +549,35 @@ export const Legal = () => {
<FormikTextField type={input.type} name={input.name} label={input.label} autoComplete="off" spellCheck={false} />

<Button
onClick={() => handleAddPolicies(input.name, (index + 5) / 4, "civilResponsibilityPolicy", input.label)}
sx={{ width: "100%" }}
onClick={() =>
handleAddPolicies(input.name, (index + 5) / 4, "civilResponsibilityPolicy", input.label, (schema) =>
setNewValidationSchema(schema)
)
}
startIcon={<AddIcon />}
variant="outlined"
>
Añadir
</Button>
</React.Fragment>
);
} else if (input.name.includes("end")) {
return (
<>
<FormikTextField
key={index}
type={input.type}
name={input.name}
label={input.label}
autoComplete="off"
spellCheck={false}
/>
<Button startIcon={<KeyboardArrowDownIcon />} sx={{ width: "100%" }} variant="contained">
Eliminar
</Button>
</>
);
}
return (
<FormikTextField key={index} type={input.type} name={input.name} label={input.label} autoComplete="off" spellCheck={false} />
Expand Down Expand Up @@ -641,7 +653,7 @@ export const Legal = () => {
</IconButton>
</DialogTitle>
<DialogContent>
<Formik initialValues={details} onSubmit={handleSubmitEdit}>
{/* <Formik initialValues={details} onSubmit={handleSubmitEdit}>
<Form>
<Box sx={{ display: "flex", gap: "1rem", pt: "0.5rem", flexWrap: "wrap" }}>
<FormikTextField type="text" name="name" label="Clientes" autoComplete="off" spellCheck={false} />
Expand Down Expand Up @@ -689,7 +701,7 @@ export const Legal = () => {
</Button>
</Box>
</Form>
</Formik>
</Formik> */}
</DialogContent>
</Dialog>
</>
Expand Down
7 changes: 5 additions & 2 deletions src/components/pages/MyPayslips.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ export const MyPayslips = () => {
if (!response.ok) {
throw new Error(data.detail);
} else if (response.status === 200) {
if (!permissions || !permissions.includes("payslip.add_payslip")) {
setRows(filtered);
if (permissions && permissions.includes("payslip.view_payslip")) {
const userPayslips = data.filter((payslip) => payslip.identification === cedula);
setRows(userPayslips);
} else {
setRows(data);
}
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/pages/Payslips.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const Payslips = () => {

useEffect(() => {
window.scrollTo(0, 0);
if (!permissions || !permissions.includes("payslip.add_payslip")) {
if (!permissions || !permissions.includes("payslip.view_payslip")) {
navigate("/logged/home");
}
}, []);
Expand Down

0 comments on commit a3e2b06

Please sign in to comment.