From 7e8ff5ee43ffb438f87bfb216a0771f32d30ffb0 Mon Sep 17 00:00:00 2001 From: Jose-Prince Date: Wed, 13 Nov 2024 14:21:43 -0600 Subject: [PATCH 1/5] Feat: First funtionalities for month calendar --- .../src/components/Calendar/MonthCalendar.tsx | 92 ++++++++++++++++--- .../src/components/Calendar/calendar.css | 3 +- .../src/components/Dashboard/GridWeek.tsx | 3 + Scrum/Working/src/pages/Dashboard.tsx | 30 +++++- Scrum/Working/src/pages/dashboard.css | 3 +- 5 files changed, 110 insertions(+), 21 deletions(-) diff --git a/Scrum/Working/src/components/Calendar/MonthCalendar.tsx b/Scrum/Working/src/components/Calendar/MonthCalendar.tsx index 2f84cef1..793beeed 100644 --- a/Scrum/Working/src/components/Calendar/MonthCalendar.tsx +++ b/Scrum/Working/src/components/Calendar/MonthCalendar.tsx @@ -1,24 +1,64 @@ +import { useEffect, useState } from 'react' import TextND from '../Txt/TextND' import './calendar.css' +import { get_contrat_by_moventh } from '../../controller/UserController' +import Note from '../Dashboard/Note' interface ContainerProps { monthMatrix: Date[][] + monthNumber: number + setModal: (modal: boolean) => void; + setSelectedNote: (note: NoteData) => void; + +} + +interface NoteData { + idtrabajo: string + trabajador: string; + dia: string; + hora: string; + descripcion: string; + precio: string; + foto: string; + timestampcita: string + pago: string } -const MonthCalendar : React.FC = ({monthMatrix}) => { +const MonthCalendar : React.FC = ({ monthMatrix, monthNumber, setModal, setSelectedNote }) => { + const [hiringsMonth, setHiringsMonth] = useState([]) + + useEffect(() => { + const data = localStorage.getItem('User') + + const fetchData = async () => { + if (data) { + const userData = JSON.parse(data) + const hirings = await get_contrat_by_moventh(userData.dpi, monthNumber.toString()) + + setHiringsMonth(hirings) + } + } + + fetchData() + }, [monthNumber]) + + useEffect(() => { + console.log("Updated hiringsMonth:", hiringsMonth); + }, [hiringsMonth]); + + return ( -
- +
- + - + @@ -29,21 +69,47 @@ const MonthCalendar : React.FC = ({monthMatrix}) => { - + { - monthMatrix.flat().map((day, index) => ( -
-
- {day.getDate() > 0 ? day.getDate() : null} + monthMatrix.flat().map((day, index) => { + // Filtramos las contrataciones que coinciden con el día actual + + return ( +
+
+
{day.getDate() > 0 ? day.getDate() : null}
+ {hiringsMonth.map((hiring, i) => ( + + <> + { + day.getDate() === new Date(hiring.timestampcita).getDate() && +
{ + setModal(true) + setSelectedNote(hiring) + console.log(hiring); + + }}> + +
+ } + + ))} +
-
- )) + ); + }) }
) } -export default MonthCalendar \ No newline at end of file +export default MonthCalendar diff --git a/Scrum/Working/src/components/Calendar/calendar.css b/Scrum/Working/src/components/Calendar/calendar.css index 3acf621e..b4ab92ea 100644 --- a/Scrum/Working/src/components/Calendar/calendar.css +++ b/Scrum/Working/src/components/Calendar/calendar.css @@ -18,8 +18,7 @@ } .daynumbers-display { - display: grid; - grid-template-rows: 300px 300px 300px 300px 300px 300px; + display: flex; padding: 10px; overflow: auto; } diff --git a/Scrum/Working/src/components/Dashboard/GridWeek.tsx b/Scrum/Working/src/components/Dashboard/GridWeek.tsx index a6300e67..e5892bb7 100644 --- a/Scrum/Working/src/components/Dashboard/GridWeek.tsx +++ b/Scrum/Working/src/components/Dashboard/GridWeek.tsx @@ -3,12 +3,15 @@ import './gridWeek.css'; import Note from './Note'; interface NoteData { + idtrabajo: string trabajador: string; dia: string; hora: string; descripcion: string; // Cambiar de 'descripción' a 'descripcion' precio: string; foto: string; + timestampcita: string + pago: string } diff --git a/Scrum/Working/src/pages/Dashboard.tsx b/Scrum/Working/src/pages/Dashboard.tsx index e05af86e..3fc54c9e 100644 --- a/Scrum/Working/src/pages/Dashboard.tsx +++ b/Scrum/Working/src/pages/Dashboard.tsx @@ -19,6 +19,8 @@ interface NoteData { descripcion: string; precio: string; foto: string; + timestampcita: string + pago: string } const Dashboard: React.FC = () => { @@ -34,7 +36,17 @@ const Dashboard: React.FC = () => { const [elementos, setElementos] = useState([]); // Estado para almacenar los datos dinámicos const [showMessage, setShowMessage] = useState(false); - const [selectedNote, setSelectedNote] = useState(null); // Estado para la Note seleccionada + const [selectedNote, setSelectedNote] = useState({ + idtrabajo: "", + trabajador: "", + dia: "", + hora: "", + descripcion: "", + precio: "", + foto: "", + timestampcita: "", + pago: "" + }); // Estado para la Note seleccionada // Función para obtener los datos de hirings const fetchHirings = async () => { @@ -95,7 +107,7 @@ const Dashboard: React.FC = () => { { } { typeCalendar === 'mes' && - + }
@@ -191,7 +208,12 @@ const Dashboard: React.FC = () => { } { typeCalendar === 'mes' && - + }
diff --git a/Scrum/Working/src/pages/dashboard.css b/Scrum/Working/src/pages/dashboard.css index 6d7a9827..62b26e10 100644 --- a/Scrum/Working/src/pages/dashboard.css +++ b/Scrum/Working/src/pages/dashboard.css @@ -10,7 +10,7 @@ /* Hide the scrollbar */ -ms-overflow-style: none; /* Internet Explorer 10+ */ - overflow-y: none; /* Scroll for y axis*/ + overflow-y: auto; /* Scroll for y axis*/ scrollbar-width: none; /* Firefox */ } @@ -68,4 +68,3 @@ .background::-webkit-scrollbar { display: none; /* Safari and Chrome */ } - From 16983114076dea6737f8874b15fcf5cea018c0b0 Mon Sep 17 00:00:00 2001 From: Jose-Prince Date: Wed, 13 Nov 2024 15:57:51 -0600 Subject: [PATCH 2/5] Feat: Visualization between all jobs and own jobs --- .../src/components/Inputs/DataList.tsx | 223 ++++++++++-------- .../components/Modals/Structures/Profile.tsx | 26 +- 2 files changed, 143 insertions(+), 106 deletions(-) diff --git a/Scrum/Working/src/components/Inputs/DataList.tsx b/Scrum/Working/src/components/Inputs/DataList.tsx index 30d46107..bc0e770c 100644 --- a/Scrum/Working/src/components/Inputs/DataList.tsx +++ b/Scrum/Working/src/components/Inputs/DataList.tsx @@ -1,15 +1,16 @@ -import React, { useEffect, useState } from 'react'; -import { IonInput, InputChangeEventDetail, IonIcon, IonPopover } from "@ionic/react"; +import React, { useEffect, useState, useCallback } from 'react'; +import { IonInput, InputChangeEventDetail, IonIcon } from "@ionic/react"; import './InputStyles.css'; import TextND from '../Txt/TextND'; import BtnAction from '../Btn/BtnAction'; import { trash, informationCircle } from 'ionicons/icons'; import { Popover, Typography } from '@mui/material'; +import { getJobsList } from '../../controller/HireControler'; interface ContainerProps { label: string; placeholder: string; - list: Array; + list: Array; value: string; setValue: (value: string) => void; validatesValue: boolean; @@ -18,122 +19,139 @@ interface ContainerProps { validation: (input: string) => boolean; } -const DataList: React.FC = ({ - label, - placeholder, - list, - value, - setValue, - validatesValue, - setValidatesValue, - errorText, - validation -}) => { - const [anchorEl, setAnchorEl] = useState(null) +type Trabajo = { + descripcion: string; + nombre_trabajo: string; +} - const [myJobs, setMyJobs] = useState>(list); - const [length, setLength] = useState(0); +const DataList: React.FC = ({ + label, + placeholder, + list, + value, + setValue, + validatesValue, + setValidatesValue, + errorText, + validation +}) => { + const [anchorEl, setAnchorEl] = useState(null); + const [popoverContent, setPopoverContent] = useState("Oficio en revisión"); + const [myJobs, setMyJobs] = useState>(list); + const [allJobs, setAllJobs] = useState>([]); const [isTouched, setIsTouched] = useState(false); useEffect(() => { - setLength(myJobs.length); - }, [myJobs]); - - const handleAddJob = () => { - setMyJobs([...myJobs, ""]); - }; + setMyJobs(list); + }, [list]); - const validate = (value: string) => { + useEffect(() => { + const fetchAllJobs = async () => { + const jobs = await getJobsList(); + setAllJobs(jobs); + }; + fetchAllJobs(); + }, []); + + const handleAddJob = useCallback(() => { + setMyJobs((prevJobs) => [...prevJobs, { nombre_trabajo: "", descripcion: "" }]); + }, []); + + const validate = useCallback((value: string) => { const isValid = validation(value); setValidatesValue(isValid); - }; - - const handleChange = (event: CustomEvent, index: number) => { - const value = (event.target as HTMLInputElement).value; - const updatedJobs = [...myJobs]; - updatedJobs[index] = value; - setMyJobs(updatedJobs); - console.log(myJobs); - - }; - - const handleDelete = (index: number) => { - const jobs = [...myJobs] - jobs.splice(index, 1) - setMyJobs(jobs) - } - - const handlePopoverClose = () => { - setAnchorEl(null) - } + }, [validation, setValidatesValue]); + + const handleChange = useCallback( + (event: CustomEvent, index: number) => { + const value = (event.target as HTMLInputElement).value; + setMyJobs((prevJobs) => { + const updatedJobs = [...prevJobs]; + updatedJobs[index] = { nombre_trabajo: value, descripcion: "" }; + return updatedJobs; + }); + }, + [] + ); - const handlePopoverOpen = (event: React.MouseEvent) => { - setAnchorEl(event.currentTarget) - } + const handleDelete = useCallback((index: number) => { + setMyJobs((prevJobs) => prevJobs.filter((_, i) => i !== index)); + }, []); + + const handlePopoverClose = useCallback(() => { + setAnchorEl(null); + }, []); + + const handlePopoverOpen = useCallback( + (event: React.MouseEvent, item: Trabajo) => { + const jobInAllJobs = allJobs.find(job => job.nombre_trabajo === item.nombre_trabajo); + setPopoverContent(jobInAllJobs ? jobInAllJobs.descripcion : "Oficio en revisión"); + setAnchorEl(event.currentTarget); + }, + [allJobs] + ); - const open = Boolean(anchorEl) + const open = Boolean(anchorEl); return ( <> - +
{myJobs.map((item, index) => ( - <> -
- - handleChange(event, index)} - onIonBlur={(event) => { - setIsTouched(true); - validate((event.target as unknown as HTMLInputElement).value); - }} - > -
- handleDelete(index)} - /> -
- - -
- - Oficio en revisión - - + +
+ handleChange(event, index)} + onIonBlur={(event) => { + setIsTouched(true); + validate((event.target as unknown as HTMLInputElement).value); + }} + > +
+ handleDelete(index)} + /> +
+ job.nombre_trabajo === item.nombre_trabajo) ? "primary" : "warning"} + onMouseEnter={(event) => handlePopoverOpen(event, item)} + onMouseLeave={handlePopoverClose} + /> +
+
))} + + {popoverContent} +
- {length < 5 && ( + {myJobs.length < 5 && (
- = ({ }; export default DataList; - diff --git a/Scrum/Working/src/components/Modals/Structures/Profile.tsx b/Scrum/Working/src/components/Modals/Structures/Profile.tsx index 46024ef5..6e4e3e10 100644 --- a/Scrum/Working/src/components/Modals/Structures/Profile.tsx +++ b/Scrum/Working/src/components/Modals/Structures/Profile.tsx @@ -1,5 +1,5 @@ import ImgInput from "../../Inputs/ImgInput" -import { useState } from "react"; +import { useEffect, useState } from "react"; import DataList from "../../Inputs/DataList"; import InputSelector from "../../Inputs/InputSelector"; import DateSelector from "../../Inputs/DateSelector"; @@ -12,6 +12,7 @@ import TextND from "../../Txt/TextND"; import HorizontalDivider from "../../Dividers/HorizontalDivider"; import BtnEditUser from "../../Btn/BtnEditUser"; import { IonButton } from "@ionic/react"; +import { getJobsWithDpi } from "../../../controller/UserController"; interface ContainerProps { user: User @@ -20,6 +21,11 @@ interface ContainerProps { working: boolean } +type Trabajo = { + descripcion: string + nombre_trabajo: string +} + type User = { nombre : string; apellidos : string; @@ -52,6 +58,8 @@ const Profile : React.FC = ({ user, setEdit, setUser, working}) const [email, setEmail] = useState(user.email) const [validatesEmail, setValidatesEmail] = useState(false) + const [jobArray, setJobArray] = useState([]) + const phoneMask = useMaskito({ options: { mask: [...Array(4).fill(/\d/),'-',...Array(4).fill(/\d/)] @@ -66,9 +74,21 @@ const Profile : React.FC = ({ user, setEdit, setUser, working}) return /^\d{4}-\d{4}$/.test(phone) } - const jobarray = ['Carpintero','Albañil','Pintor',] const sexos : Array = ['Masculino', 'Femenino'] + useEffect(() => { + const fetchJobs = async () => { + const jobs = await getJobsWithDpi(user.dpi) + console.log(jobs); + + setJobArray(jobs) + } + + fetchJobs() + console.log(jobArray); + + },[user.dpi]) + return ( <>
@@ -81,7 +101,7 @@ const Profile : React.FC = ({ user, setEdit, setUser, working}) {working && <> - + }
From f09cfeb43ea4717f442eef8180f815708c223621 Mon Sep 17 00:00:00 2001 From: Jose-Prince Date: Wed, 13 Nov 2024 16:33:44 -0600 Subject: [PATCH 3/5] Feat: autocomplete for jobs saved --- .../src/components/Inputs/DataList.tsx | 69 +++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/Scrum/Working/src/components/Inputs/DataList.tsx b/Scrum/Working/src/components/Inputs/DataList.tsx index bc0e770c..9113b857 100644 --- a/Scrum/Working/src/components/Inputs/DataList.tsx +++ b/Scrum/Working/src/components/Inputs/DataList.tsx @@ -4,7 +4,7 @@ import './InputStyles.css'; import TextND from '../Txt/TextND'; import BtnAction from '../Btn/BtnAction'; import { trash, informationCircle } from 'ionicons/icons'; -import { Popover, Typography } from '@mui/material'; +import { Popover, Typography, List, ListItem, ListItemText } from '@mui/material'; import { getJobsList } from '../../controller/HireControler'; interface ContainerProps { @@ -39,10 +39,12 @@ const DataList: React.FC = ({ const [popoverContent, setPopoverContent] = useState("Oficio en revisión"); const [myJobs, setMyJobs] = useState>(list); const [allJobs, setAllJobs] = useState>([]); + const [filteredJobs, setFilteredJobs] = useState>>([]); const [isTouched, setIsTouched] = useState(false); useEffect(() => { setMyJobs(list); + setFilteredJobs(Array(list.length).fill([])); // Initialize filteredJobs for each input }, [list]); useEffect(() => { @@ -55,6 +57,7 @@ const DataList: React.FC = ({ const handleAddJob = useCallback(() => { setMyJobs((prevJobs) => [...prevJobs, { nombre_trabajo: "", descripcion: "" }]); + setFilteredJobs((prevFilteredJobs) => [...prevFilteredJobs, []]); // Add empty list for new input }, []); const validate = useCallback((value: string) => { @@ -65,17 +68,53 @@ const DataList: React.FC = ({ const handleChange = useCallback( (event: CustomEvent, index: number) => { const value = (event.target as HTMLInputElement).value; + + // Filtrar sugerencias solo para el campo actual y evitar mostrar coincidencias exactas + if (value.length > 2) { + const jobSuggestions = allJobs.filter(job => + job.nombre_trabajo.toLowerCase().includes(value.toLowerCase()) && + job.nombre_trabajo.toLowerCase() !== value.toLowerCase() + ); + setFilteredJobs((prevFilteredJobs) => { + const newFilteredJobs = [...prevFilteredJobs]; + newFilteredJobs[index] = jobSuggestions; + return newFilteredJobs; + }); + } else { + setFilteredJobs((prevFilteredJobs) => { + const newFilteredJobs = [...prevFilteredJobs]; + newFilteredJobs[index] = []; + return newFilteredJobs; + }); + } + setMyJobs((prevJobs) => { const updatedJobs = [...prevJobs]; updatedJobs[index] = { nombre_trabajo: value, descripcion: "" }; return updatedJobs; }); }, - [] + [allJobs] ); + const handleSelectJob = (job: Trabajo, index: number) => { + setMyJobs((prevJobs) => { + const updatedJobs = [...prevJobs]; + updatedJobs[index] = job; + return updatedJobs; + }); + + // Limpiar sugerencias después de seleccionar una opción + setFilteredJobs((prevFilteredJobs) => { + const newFilteredJobs = [...prevFilteredJobs]; + newFilteredJobs[index] = []; + return newFilteredJobs; + }); + }; + const handleDelete = useCallback((index: number) => { setMyJobs((prevJobs) => prevJobs.filter((_, i) => i !== index)); + setFilteredJobs((prevFilteredJobs) => prevFilteredJobs.filter((_, i) => i !== index)); }, []); const handlePopoverClose = useCallback(() => { @@ -99,7 +138,7 @@ const DataList: React.FC = ({
{myJobs.map((item, index) => ( -
+
= ({ setIsTouched(true); validate((event.target as unknown as HTMLInputElement).value); }} - > + autocomplete="off" // Desactivar autocompletado del navegador + /> + {filteredJobs[index]?.length > 0 && ( + + {filteredJobs[index].map((job, jobIndex) => ( + handleSelectJob(job, index)} + > + + + ))} + + )}
Date: Wed, 13 Nov 2024 18:15:03 -0600 Subject: [PATCH 4/5] Feat: Add jobs into neo4J for workers --- .../src/components/Btn/BtnEditUser.tsx | 47 +++++++++++++++++-- .../src/components/Inputs/DataList.tsx | 11 +++-- .../components/Modals/Structures/Profile.tsx | 9 +++- 3 files changed, 60 insertions(+), 7 deletions(-) diff --git a/Scrum/Working/src/components/Btn/BtnEditUser.tsx b/Scrum/Working/src/components/Btn/BtnEditUser.tsx index df8342ca..78539d78 100644 --- a/Scrum/Working/src/components/Btn/BtnEditUser.tsx +++ b/Scrum/Working/src/components/Btn/BtnEditUser.tsx @@ -1,7 +1,9 @@ import { IonButton } from "@ionic/react"; import './BtnStyles.css'; -import React from "react"; -import { updatecuenta, updatecuentaNEO4J } from "../../controller/UserController"; +import React, { useEffect, useState } from "react"; +import { addJobToWorker, getJobsWithDpi, updatecuenta, updatecuentaNEO4J } from "../../controller/UserController"; +import { getJobsList } from "../../controller/HireControler"; +import { addjob_toprofile } from "../../controller/Admin_Controller"; type User = { nombre : string; @@ -20,6 +22,11 @@ type User = { isworking: boolean; }; + type Trabajo = { + descripcion: string + nombre_trabajo: string +} + interface ContainerProps { user: User; banner: string; @@ -35,6 +42,7 @@ interface ContainerProps { validatesCell: boolean setUser: (user: User) => void setEdit: (edit: boolean) => void + list : Array } const BtnEditUser: React.FC = ({ @@ -50,9 +58,30 @@ const BtnEditUser: React.FC = ({ municipio, validateBirthdate, validateEmail, - validatesCell + validatesCell, + list }) => { + const [allJobs, setAllJobs] = useState>([]); + const [myJobs, setMyJobs] = useState>([]); + + useEffect(() => { + const fetchJobs = async () => { + const jobs = await getJobsWithDpi(user.dpi) + setMyJobs(jobs) + } + + fetchJobs() + },[user.dpi]) + + useEffect(() => { + const fetchAllJobs = async () => { + const jobs = await getJobsList(); + setAllJobs(jobs); + }; + fetchAllJobs(); + }, []); + const handleClick = () => { const updatedUser = { ...user, @@ -65,6 +94,18 @@ const BtnEditUser: React.FC = ({ municipio: municipio }; + const jobsNotInMyJobs = list.filter( + (jobInList) => !myJobs.some((jobInMyJobs) => jobInMyJobs.nombre_trabajo === jobInList.nombre_trabajo) + ) + + jobsNotInMyJobs.forEach((job) => { + if (allJobs.some((jobInAllJobs) => jobInAllJobs.nombre_trabajo === job.nombre_trabajo)) { + addJobToWorker(user.dpi, job.nombre_trabajo) + } else { + addjob_toprofile(job.nombre_trabajo, user.dpi) + } + }) + localStorage.setItem('User', JSON.stringify(updatedUser)); setUser(updatedUser); if (validateBirthdate && validateEmail && validatesCell ) { diff --git a/Scrum/Working/src/components/Inputs/DataList.tsx b/Scrum/Working/src/components/Inputs/DataList.tsx index 9113b857..45a50708 100644 --- a/Scrum/Working/src/components/Inputs/DataList.tsx +++ b/Scrum/Working/src/components/Inputs/DataList.tsx @@ -11,6 +11,7 @@ interface ContainerProps { label: string; placeholder: string; list: Array; + setList : (list : Array) => void value: string; setValue: (value: string) => void; validatesValue: boolean; @@ -33,7 +34,8 @@ const DataList: React.FC = ({ validatesValue, setValidatesValue, errorText, - validation + validation, + setList }) => { const [anchorEl, setAnchorEl] = useState(null); const [popoverContent, setPopoverContent] = useState("Oficio en revisión"); @@ -44,9 +46,8 @@ const DataList: React.FC = ({ useEffect(() => { setMyJobs(list); - setFilteredJobs(Array(list.length).fill([])); // Initialize filteredJobs for each input }, [list]); - + useEffect(() => { const fetchAllJobs = async () => { const jobs = await getJobsList(); @@ -55,6 +56,10 @@ const DataList: React.FC = ({ fetchAllJobs(); }, []); + useEffect(() => { + setList(myJobs) + },[myJobs]) + const handleAddJob = useCallback(() => { setMyJobs((prevJobs) => [...prevJobs, { nombre_trabajo: "", descripcion: "" }]); setFilteredJobs((prevFilteredJobs) => [...prevFilteredJobs, []]); // Add empty list for new input diff --git a/Scrum/Working/src/components/Modals/Structures/Profile.tsx b/Scrum/Working/src/components/Modals/Structures/Profile.tsx index 6e4e3e10..cbff8864 100644 --- a/Scrum/Working/src/components/Modals/Structures/Profile.tsx +++ b/Scrum/Working/src/components/Modals/Structures/Profile.tsx @@ -89,6 +89,12 @@ const Profile : React.FC = ({ user, setEdit, setUser, working}) },[user.dpi]) + useEffect(() => { + console.log(jobArray); + + },[jobArray]) + + return ( <>
@@ -101,7 +107,7 @@ const Profile : React.FC = ({ user, setEdit, setUser, working}) {working && <> - + }
@@ -179,6 +185,7 @@ const Profile : React.FC = ({ user, setEdit, setUser, working}) municipio={municipio} setUser={setUser} setEdit={setEdit} + list={jobArray} />
From 20e59fec6096abe748d0ca91987b5659bee385c0 Mon Sep 17 00:00:00 2001 From: Jose-Prince Date: Wed, 13 Nov 2024 18:29:00 -0600 Subject: [PATCH 5/5] Feat: Delete Jobs for a worker --- Scrum/Working/src/components/Inputs/DataList.tsx | 11 ++++++++++- .../src/components/Modals/Structures/Profile.tsx | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Scrum/Working/src/components/Inputs/DataList.tsx b/Scrum/Working/src/components/Inputs/DataList.tsx index 45a50708..230acc5d 100644 --- a/Scrum/Working/src/components/Inputs/DataList.tsx +++ b/Scrum/Working/src/components/Inputs/DataList.tsx @@ -6,6 +6,7 @@ import BtnAction from '../Btn/BtnAction'; import { trash, informationCircle } from 'ionicons/icons'; import { Popover, Typography, List, ListItem, ListItemText } from '@mui/material'; import { getJobsList } from '../../controller/HireControler'; +import { deleteJobToWorker } from '../../controller/UserController'; interface ContainerProps { label: string; @@ -18,6 +19,7 @@ interface ContainerProps { setValidatesValue: (validatesJob: boolean) => void; errorText: string; validation: (input: string) => boolean; + dpi: string } type Trabajo = { @@ -35,7 +37,8 @@ const DataList: React.FC = ({ setValidatesValue, errorText, validation, - setList + setList, + dpi }) => { const [anchorEl, setAnchorEl] = useState(null); const [popoverContent, setPopoverContent] = useState("Oficio en revisión"); @@ -118,6 +121,12 @@ const DataList: React.FC = ({ }; const handleDelete = useCallback((index: number) => { + const jobToDelete = myJobs[index] + + if (allJobs.some((job) => job.nombre_trabajo === jobToDelete.nombre_trabajo)) { + deleteJobToWorker(dpi, jobToDelete.nombre_trabajo) + } + setMyJobs((prevJobs) => prevJobs.filter((_, i) => i !== index)); setFilteredJobs((prevFilteredJobs) => prevFilteredJobs.filter((_, i) => i !== index)); }, []); diff --git a/Scrum/Working/src/components/Modals/Structures/Profile.tsx b/Scrum/Working/src/components/Modals/Structures/Profile.tsx index cbff8864..11c64f02 100644 --- a/Scrum/Working/src/components/Modals/Structures/Profile.tsx +++ b/Scrum/Working/src/components/Modals/Structures/Profile.tsx @@ -107,7 +107,7 @@ const Profile : React.FC = ({ user, setEdit, setUser, working}) {working && <> - + }