codis quasi del tot bé. Cal repassar les dates condicionals d'inici i fi
This commit is contained in:
parent
b61adc4f91
commit
6b3944277d
@ -10,20 +10,12 @@ import { Roles } from 'meteor/roles';
|
||||
// import { useUserId } from 'meteor/react-meteor-accounts';
|
||||
import Select from 'react-select';
|
||||
|
||||
// import CreatableSelect from 'react-select/creatable';
|
||||
// import AsyncCreatableSelect from 'react-select/async-creatable';
|
||||
// import { BarraNav } from "./BarraNav/BarraNav";
|
||||
|
||||
// import InfiniteCalendar from 'react-infinite-calendar';
|
||||
// import 'react-infinite-calendar/styles.css';
|
||||
|
||||
function generaCodi() {
|
||||
return Random.id().slice(0, 5).toUpperCase();
|
||||
}
|
||||
|
||||
export const Codis = () => {
|
||||
|
||||
// const [permes, setPermes] = useState(false);
|
||||
const [esEditor, setEsEditor] = useState(false);
|
||||
const userId = Meteor.userId();
|
||||
|
||||
@ -36,10 +28,6 @@ export const Codis = () => {
|
||||
})();
|
||||
}, []);
|
||||
|
||||
// console.log("isAdmin: ", isAdmin) ;
|
||||
|
||||
// const [ambitSeleccionat, setAmbitSeleccionat] = useState(null);
|
||||
|
||||
const [confecCodObj, setConfecCodObj] = useState({
|
||||
codi: generaCodi(),
|
||||
ambit: null,
|
||||
@ -50,9 +38,6 @@ export const Codis = () => {
|
||||
condFi: null
|
||||
});
|
||||
|
||||
// useSubscribe('necessitats');
|
||||
// const necessitats = useTracker("necessitats", () => NecessitatsCollection.find().fetchAsync());
|
||||
|
||||
useSubscribe('codis');
|
||||
const codis = useTracker("codis", () => CodisCollection.find().fetchAsync());
|
||||
|
||||
@ -60,29 +45,10 @@ export const Codis = () => {
|
||||
const pobles = useTracker("pobles", () => PoblesCollection.find().fetchAsync());
|
||||
const ambits = pobles?.map(p => p?.ambitAssociat);
|
||||
|
||||
// console.log("ambits: ", ambits);
|
||||
|
||||
// useSubscribe('tipus');
|
||||
// const ambits = useTracker("ambits", () => Collection.find().fetchAsync());
|
||||
|
||||
// console.log("tipus: ", tipus);
|
||||
// console.log("necessitats: ", necessitats);
|
||||
|
||||
// console.log("tipusSeleccionat: ", tipusSeleccionat);
|
||||
|
||||
|
||||
// const filterAmbit = (inputValue) => {
|
||||
// return ambits.filter((i) =>
|
||||
// i.toLowerCase().includes(inputValue.toLowerCase())
|
||||
// );
|
||||
// };
|
||||
// const [ambitGeneral, setAmbitGeneral] = useState(ambitSeleccionat === "GENERAL");
|
||||
const codiDoc = useTracker("valsFormDoc", () => CodisCollection.findOneAsync(codiSeleccionat?._id));
|
||||
|
||||
// let selRolVal = codiDoc?.rol || "usuari";
|
||||
|
||||
const SelectorDeRol = () => {
|
||||
// const [docRol, setDocRol] = useState(codiDoc?.rol)
|
||||
|
||||
return <>
|
||||
<label htmlFor="selRol">Rol: </label>
|
||||
@ -90,7 +56,7 @@ export const Codis = () => {
|
||||
required
|
||||
key={Math.random()}
|
||||
name="selRol"
|
||||
// filterOption={(opts) => necessitats.find(nec => nec.tipus === tipusSeleccionat._id)}
|
||||
|
||||
defaultValue={
|
||||
codiSeleccionat
|
||||
? {
|
||||
@ -99,26 +65,19 @@ export const Codis = () => {
|
||||
}
|
||||
|
||||
: confecCodObj?.rol || null
|
||||
// ? {
|
||||
// label: confecCodObj.rol,
|
||||
// value: confecCodObj.rol
|
||||
// }
|
||||
|
||||
// : null
|
||||
// docRol && {label: docRol, value: docRol}
|
||||
}
|
||||
|
||||
onChange={v => {
|
||||
console.log("v: ", v);
|
||||
// console.log("v: ", v);
|
||||
|
||||
console.log("cCO abans: ", confecCodObj);
|
||||
// setDocRol(v);
|
||||
// console.log("cCO abans: ", confecCodObj);
|
||||
setConfecCodObj({
|
||||
...confecCodObj,
|
||||
rol: v
|
||||
});
|
||||
|
||||
console.log("cCO despres: ", confecCodObj);
|
||||
// console.log("cCO despres: ", confecCodObj);
|
||||
}}
|
||||
|
||||
options={
|
||||
@ -162,8 +121,8 @@ export const Codis = () => {
|
||||
|
||||
const codSelAbsActChecked = codiDoc ? {checked: codiDoc.absActiu} : {defaultChecked: confecCodObj.absActiu};
|
||||
|
||||
console.log("cS: ", codiSeleccionat);
|
||||
console.log("cCO: ", confecCodObj);
|
||||
// console.log("cS: ", codiSeleccionat);
|
||||
// console.log("cCO: ", confecCodObj);
|
||||
|
||||
return <div style={{
|
||||
display: `inline-block`,
|
||||
@ -174,17 +133,8 @@ export const Codis = () => {
|
||||
outline: `${codiSeleccionat?._id ? '5px solid black' : 'none'}`
|
||||
}}>
|
||||
|
||||
{/* {ambitSeleccionat && <h1>{ambitSeleccionat?.value}</h1>} */}
|
||||
<h1>Codis</h1>
|
||||
|
||||
{/* <button
|
||||
onClick={ev => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
setCodiGenerat(generaCodi());
|
||||
}}
|
||||
>Genera el codi</button> */}
|
||||
|
||||
<div
|
||||
style={{
|
||||
@ -208,7 +158,6 @@ export const Codis = () => {
|
||||
|
||||
<form
|
||||
action={d => {
|
||||
// if (d.get('selTipus'))
|
||||
try {
|
||||
Meteor.callAsync('editaOAfigCodi', {
|
||||
...codiGenerat || [],
|
||||
@ -216,7 +165,6 @@ export const Codis = () => {
|
||||
ambit: d.get('selAmbit') || "",
|
||||
rol: d.get('selRol'),
|
||||
|
||||
// act_abs: d.get('activAbs'),
|
||||
absCond,
|
||||
absActiu: d.get('absActiu'),
|
||||
condIni: d.get('condIni'),
|
||||
@ -235,17 +183,11 @@ export const Codis = () => {
|
||||
}}
|
||||
>
|
||||
<label htmlFor="selAmbit">Àmbit: </label>
|
||||
{/* Si
|
||||
l'usuari és ADMINISTRADOR o té permisos de responsabilitat, podrà crear nous Tipus al CREAR o a l'EDITAR
|
||||
si no
|
||||
tansols podrà assignar a un tipus predefinit o al de ALTRES
|
||||
*/}
|
||||
|
||||
<Select
|
||||
required
|
||||
name="selAmbit"
|
||||
// formatCreateLabel={(inputValue) => "Crear nou tipus..."}
|
||||
// filterOption={filterAmbit}
|
||||
|
||||
defaultValue={codiDoc && {
|
||||
label: codiDoc?.ambit,
|
||||
value: codiDoc?.ambit
|
||||
@ -264,12 +206,8 @@ export const Codis = () => {
|
||||
}
|
||||
]
|
||||
}
|
||||
// onCreateOption={(inputValue) => Meteor.callAsync('afigT', {titol: inputValue})}
|
||||
isSearchable
|
||||
// loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))}
|
||||
onChange={amb => {
|
||||
// setAmbitSeleccionat(amb);
|
||||
// console.log("amb: ", amb);
|
||||
|
||||
setConfecCodObj({
|
||||
...confecCodObj,
|
||||
@ -278,19 +216,11 @@ export const Codis = () => {
|
||||
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* <select name="selTipus">
|
||||
<option value="moble">Moble</option>
|
||||
<option value="maquinari">Maquinari</option>
|
||||
<option value="menjar">Menjar i beguda</option>
|
||||
<option value="infantil">Infantils</option>
|
||||
<option value="higiene">Higiene</option>
|
||||
</select> */}
|
||||
|
||||
<br />
|
||||
|
||||
<SelectorDeRol />
|
||||
{/* {... {ambitSeleccionat, selRolVal}} /> */}
|
||||
|
||||
|
||||
<br /><br />
|
||||
|
||||
@ -304,52 +234,82 @@ export const Codis = () => {
|
||||
backgroundColor: `lightslategray`
|
||||
}}>
|
||||
{/* <p>TEMPS REAL:</p> */}
|
||||
<input
|
||||
type="radio"
|
||||
name='absCond'
|
||||
value="abs"
|
||||
// defaultChecked={codiDoc?.act_abs === "on"}
|
||||
// checked={absCond === 'abs'}
|
||||
// onChange={(ev) => setAbsCond('abs')}
|
||||
<label htmlFor="inActAbs">
|
||||
<input
|
||||
type="radio"
|
||||
name='absCond'
|
||||
value="abs"
|
||||
id="inActAbs"
|
||||
|
||||
checked={codiSeleccionat && codiSeleccionat.absCond === 'abs' || confecCodObj?.absCond === 'abs'}
|
||||
onChange={(ev) => setConfecCodObj({
|
||||
...confecCodObj,
|
||||
absCond: 'abs'
|
||||
})}
|
||||
/>
|
||||
<label
|
||||
htmlFor="absCond"
|
||||
|
||||
onClick={() => setConfecCodObj({
|
||||
...confecCodObj,
|
||||
absCond: 'abs'
|
||||
})}>Activació absoluta</label>
|
||||
checked={
|
||||
codiSeleccionat
|
||||
&&
|
||||
codiSeleccionat.absCond === 'abs'
|
||||
|
||||
||
|
||||
|
||||
confecCodObj?.absCond === 'abs'
|
||||
&&
|
||||
!codiSeleccionat
|
||||
}
|
||||
|
||||
onChange={(ev) => {
|
||||
if (codiSeleccionat) {
|
||||
Meteor.callAsync('modActivacioAbsolutaCodi', codiSeleccionat);
|
||||
setCodiSeleccionat({
|
||||
...codiSeleccionat,
|
||||
absCond: 'abs'
|
||||
});
|
||||
} else {
|
||||
setConfecCodObj({
|
||||
...confecCodObj,
|
||||
absCond: 'abs'
|
||||
})
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<span>Activació absoluta</span>
|
||||
</label>
|
||||
|
||||
<br />
|
||||
|
||||
{/* L'activació condicionada desactivada fa que no siguen 'required' les dates d'inici i final */}
|
||||
<label htmlFor="inActCond">
|
||||
<input
|
||||
type="radio"
|
||||
name='absCond'
|
||||
value="cond"
|
||||
id="inActCond"
|
||||
|
||||
checked={
|
||||
codiSeleccionat
|
||||
&&
|
||||
codiSeleccionat.absCond === 'cond'
|
||||
|
||||
||
|
||||
|
||||
confecCodObj?.absCond === 'cond'
|
||||
&&
|
||||
!codiSeleccionat
|
||||
}
|
||||
|
||||
<input
|
||||
type="radio"
|
||||
name='absCond'
|
||||
value="cond"
|
||||
|
||||
// checked={absCond === 'cond'}
|
||||
// onChange={(ev) => setAbsCond('cond')}
|
||||
checked={codiSeleccionat && codiSeleccionat.absCond === 'cond' || confecCodObj?.absCond === 'cond'}
|
||||
onChange={(ev) => setConfecCodObj({
|
||||
...confecCodObj,
|
||||
absCond: 'cond'
|
||||
})}
|
||||
onChange={(ev) => {
|
||||
if (codiSeleccionat) {
|
||||
Meteor.callAsync('modActivacioAbsolutaCodi', codiSeleccionat);
|
||||
setCodiSeleccionat({
|
||||
...codiSeleccionat,
|
||||
absCond: 'cond'
|
||||
});
|
||||
} else {
|
||||
setConfecCodObj({
|
||||
...confecCodObj,
|
||||
absCond: 'cond'
|
||||
})
|
||||
}
|
||||
|
||||
/>
|
||||
<label htmlFor="absCond" onClick={
|
||||
() => setConfecCodObj({
|
||||
...confecCodObj,
|
||||
absCond: 'cond'
|
||||
})
|
||||
}>Activació condicionada</label>
|
||||
}}
|
||||
/>
|
||||
<span>Activació condicionada</span>
|
||||
</label>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
@ -370,6 +330,8 @@ export const Codis = () => {
|
||||
confecCodObj?.absCond === 'abs'
|
||||
)
|
||||
&&
|
||||
codiSeleccionat?.absCond !== 'cond'
|
||||
&&
|
||||
|
||||
<>
|
||||
<label htmlFor="act_status">Actiu</label>
|
||||
@ -382,8 +344,6 @@ export const Codis = () => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
// console.log("ev: ", ev);
|
||||
|
||||
if (codiSeleccionat) {
|
||||
Meteor.callAsync('modActivacioAbsolutaCodi', codiSeleccionat);
|
||||
setCodiSeleccionat({
|
||||
@ -400,18 +360,20 @@ export const Codis = () => {
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
// codiDoc &&
|
||||
// Meteor.callAsync('modActivacioAbsolutaCodi', codiDoc);
|
||||
}
|
||||
{
|
||||
codiSeleccionat
|
||||
(codiSeleccionat
|
||||
&&
|
||||
codiSeleccionat.absCond === 'cond'
|
||||
|
||||
||
|
||||
|
||||
confecCodObj?.absCond === 'cond'
|
||||
)
|
||||
&&
|
||||
codiSeleccionat?.absCond !== 'abs'
|
||||
&&
|
||||
|
||||
<>
|
||||
<p
|
||||
style={{
|
||||
@ -425,7 +387,7 @@ export const Codis = () => {
|
||||
name="condIni"
|
||||
onChange={v => {
|
||||
|
||||
console.log("dataIni: ", v.currentTarget.value);
|
||||
// console.log("dataIni: ", v.currentTarget.value);
|
||||
setConfecCodObj({
|
||||
...confecCodObj,
|
||||
condIni: v.currentTarget.value
|
||||
@ -440,7 +402,7 @@ export const Codis = () => {
|
||||
type="date"
|
||||
name="condFi"
|
||||
onChange={v => {
|
||||
console.log("dataFi: ", v.currentTarget.value);
|
||||
// console.log("dataFi: ", v.currentTarget.value);
|
||||
setConfecCodObj({
|
||||
...confecCodObj,
|
||||
condFi: v.currentTarget.value
|
||||
@ -453,26 +415,9 @@ export const Codis = () => {
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* <select name="s.
|
||||
elPoble">
|
||||
{
|
||||
pobles.map((v,i) => <option key={`optPob${i}`}>{v.nomPoble}</option>)
|
||||
}
|
||||
</select> */}
|
||||
|
||||
|
||||
|
||||
|
||||
<input type='submit' value="Donar d'alta el codi" />
|
||||
|
||||
{/* {ambitSeleccionat && esEditor && <button onClick={ev => {
|
||||
ev.preventDefault();
|
||||
if (confirm(`Vas a eliminar el poble "${pobleSeleccionat.nomPoble}". És una operació irreversible. Procedir?`)) {
|
||||
Meteor.callAsync('eliminaPoble', pobleSeleccionat._id).catch(err => console.error(err));
|
||||
setNecessitatSeleccionada(null);
|
||||
}
|
||||
}}>Elimina</button>} */}
|
||||
</form>
|
||||
</div>;
|
||||
};
|
||||
@ -482,24 +427,12 @@ export const Codis = () => {
|
||||
lastWeek = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7)
|
||||
;
|
||||
|
||||
// console.log("codis: ", codis);
|
||||
|
||||
|
||||
return <Suspense fallback={<>Carregant...</>} >
|
||||
|
||||
<QuadreInfo_Codis />
|
||||
|
||||
<br /><br />
|
||||
|
||||
{/* <AsyncCreatableSelect
|
||||
cacheOptions
|
||||
defaultOptions={tipus.map((v,i) => ({value: v, label: v.titol})) }
|
||||
loadOptions={tipus.map((v,i) => ({value: v, label: v.titol}))}
|
||||
/> */}
|
||||
|
||||
{/* <SelectSearch options={options} value="sv" name="language" placeholder="Choose your language" /> */}
|
||||
|
||||
|
||||
<ul style={{
|
||||
display: `flex`,
|
||||
flexWrap: `wrap`,
|
||||
@ -508,8 +441,7 @@ export const Codis = () => {
|
||||
alignContent: `space-around`
|
||||
}}>{
|
||||
codis
|
||||
// .reverse()
|
||||
// .sort((a,b) => a?.codi?.editedAt < b?.codi?.editedAt)
|
||||
|
||||
.map(cod => <li
|
||||
key={cod._id}
|
||||
style={{
|
||||
@ -526,7 +458,6 @@ export const Codis = () => {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
|
||||
// console.log("codSel: ", codiSeleccionat);
|
||||
setCodiSeleccionat(codiSeleccionat?._id === cod._id ? null : cod);
|
||||
}}
|
||||
>
|
||||
@ -550,16 +481,9 @@ export const Codis = () => {
|
||||
}}
|
||||
/>
|
||||
{cod.codi}
|
||||
{/* {esEditor && <button onClick={() => {setAmbitSeleccionat({value: cod, label: cod})}}>Edita</button>} */}
|
||||
|
||||
</li>)
|
||||
}</ul>
|
||||
|
||||
{/* <InfiniteCalendar
|
||||
width={400}
|
||||
height={600}
|
||||
selected={today}
|
||||
disabledDays={[0,6]}
|
||||
minDate={lastWeek}
|
||||
/> */}
|
||||
</Suspense>;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user