changes
This commit is contained in:
parent
df1d26f653
commit
26a54912cd
@ -1,4 +1,4 @@
|
|||||||
import React, { ChangeEvent, useContext, useEffect, useState } from 'react';
|
import React, { ChangeEvent, useContext, useEffect, useMemo, useState } from 'react';
|
||||||
import Modal from '@material-ui/core/Modal';
|
import Modal from '@material-ui/core/Modal';
|
||||||
import Fade from '@material-ui/core/Fade';
|
import Fade from '@material-ui/core/Fade';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
@ -25,20 +25,27 @@ const useStyles = makeStyles({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const Input = styled.input`
|
const SaveButton = styled.div`
|
||||||
font-family: 'Roboto', sans-serif;
|
display: flex;
|
||||||
font-size: 18px;
|
justify-content: center;
|
||||||
background-color: #f1f2f5;
|
align-items: center;
|
||||||
|
user-select: none;
|
||||||
|
background-color: #43a047;
|
||||||
|
border-radius: 10px;
|
||||||
|
cursor: pointer;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
max-height: 40px;
|
margin-bottom: 10px;
|
||||||
width: 100%;
|
&:hover {
|
||||||
border: none;
|
color: #ffffff;
|
||||||
margin-left: 5px;
|
box-shadow: 0px 5px 4px 0px rgba(0, 0, 0, 0.24);
|
||||||
&:focus {
|
|
||||||
outline: none;
|
|
||||||
}
|
}
|
||||||
`;
|
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background-color: #54c457;
|
||||||
|
}
|
||||||
|
|
||||||
|
box-shadow: 3px 3px 3px 0px rgba(0, 0, 0, 0.75);
|
||||||
|
`;
|
||||||
const TransferStyled = styled.div`
|
const TransferStyled = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@ -100,7 +107,7 @@ const createExchange = async (groupsIds: Array<number>) => {
|
|||||||
try {
|
try {
|
||||||
const response = await axiosInstance.post(
|
const response = await axiosInstance.post(
|
||||||
`${process.env.REACT_APP_API_URL}/api/v1/exchanges/exchange`,
|
`${process.env.REACT_APP_API_URL}/api/v1/exchanges/exchange`,
|
||||||
JSON.stringify(groupsIds),
|
JSON.stringify({ assignment: groupsIds[0], group: groupsIds[1] }),
|
||||||
);
|
);
|
||||||
console.log('create exchange response is: ', response);
|
console.log('create exchange response is: ', response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -109,29 +116,50 @@ const createExchange = async (groupsIds: Array<number>) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => {
|
export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => {
|
||||||
const { basket } = useContext(coursesContext)!;
|
const { basket, selectBasketCourses } = useContext(coursesContext)!;
|
||||||
|
// const basketCourseGroups = useMemo(() => selectBasketCourseGroups(course.name), []);
|
||||||
|
const basketCourses = selectBasketCourses();
|
||||||
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
// const groups = selectGroups();
|
// const groups = selectGroups();
|
||||||
const [input, setInput] = useState('');
|
const [input, setInput] = useState('');
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
const [assignmentsGroups, setAssignmentsGroups] = useState<Array<any>>([]);
|
const [assignmentsClasses, setAssignmentsClasses] = useState<Array<any>>([]);
|
||||||
const [selectedAssignmentsGroup, setSelectedAssignmentsGroup] = useState<any>('');
|
const [selectedAssignmentsClasses, setSelectedAssignmentsClasses] = useState<any>('');
|
||||||
|
const [groups, setGroups] = useState<any>([]);
|
||||||
const [selectedGroup, setSelectedGroup] = useState<any>('');
|
const [selectedGroup, setSelectedGroup] = useState<any>('');
|
||||||
const [exchanges, setExchanges] = useState<any>(null);
|
const [exchanges, setExchanges] = useState<any>(null);
|
||||||
// const allGroups
|
// const allGroups
|
||||||
const handleSelectedAssignmentsGroupChange = (event: React.ChangeEvent<{ value: unknown }>) => {
|
const handleSelectedAssignmentsGroupChange = (event: React.ChangeEvent<{ value: unknown }>) => {
|
||||||
console.log('it is: ', event.target.value);
|
console.log('it is: ', event.target.value);
|
||||||
setSelectedAssignmentsGroup(event.target.value);
|
setSelectedAssignmentsClasses(event.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectedGroupChange = (event: React.ChangeEvent<{ value: unknown }>) => {
|
const handleGroupsChange = (event: React.ChangeEvent<{ value: unknown }>) => {
|
||||||
setSelectedGroup(event.target.value as any);
|
setSelectedGroup(event.target.value as any);
|
||||||
};
|
};
|
||||||
const handleChange = (event: ChangeEvent<HTMLInputElement>) => setInput(event.target.value);
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => setInput(event.target.value);
|
||||||
const handleShowDropdown = () => setOpen(true);
|
const handleShowDropdown = () => setOpen(true);
|
||||||
|
|
||||||
const handleCloseDropdown = () => setOpen(false);
|
const handleCloseDropdown = () => setOpen(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (selectedAssignmentsClasses) {
|
||||||
|
const allGroups = basketCourses.filter((el) => el.name === selectedAssignmentsClasses.name);
|
||||||
|
const allClasses = allGroups[0]?.classes;
|
||||||
|
console.log('allgroups: ', allGroups);
|
||||||
|
console.log('allclasses: ', allClasses);
|
||||||
|
if (allClasses) {
|
||||||
|
const filteredClasses = allClasses.filter((el: any) => {
|
||||||
|
return el.time !== selectedAssignmentsClasses.time;
|
||||||
|
});
|
||||||
|
console.log('filtered classes: ', filteredClasses);
|
||||||
|
setGroups(filteredClasses);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [selectedAssignmentsClasses]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getExchanges = async () => {
|
const getExchanges = async () => {
|
||||||
try {
|
try {
|
||||||
@ -147,7 +175,7 @@ export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => {
|
|||||||
const { data } = await axiosInstance.get(`${process.env.REACT_APP_API_URL}/api/v1/commisions/user/assignments`);
|
const { data } = await axiosInstance.get(`${process.env.REACT_APP_API_URL}/api/v1/commisions/user/assignments`);
|
||||||
console.log('assignments: ', data);
|
console.log('assignments: ', data);
|
||||||
const classes = data.filter((el: any) => el.type === 'CLASS');
|
const classes = data.filter((el: any) => el.type === 'CLASS');
|
||||||
setAssignmentsGroups(classes);
|
setAssignmentsClasses(classes);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
@ -175,15 +203,15 @@ export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => {
|
|||||||
<Select
|
<Select
|
||||||
labelId="demo-simple-select-label"
|
labelId="demo-simple-select-label"
|
||||||
id="assignments-groups"
|
id="assignments-groups"
|
||||||
value={selectedAssignmentsGroup}
|
value={selectedAssignmentsClasses}
|
||||||
onChange={handleSelectedAssignmentsGroupChange}
|
onChange={handleSelectedAssignmentsGroupChange}
|
||||||
placeholder="Wyszukaj..."
|
placeholder="Wyszukaj..."
|
||||||
style={{ width: '200px' }}
|
style={{ width: '200px' }}
|
||||||
>
|
>
|
||||||
{assignmentsGroups.map((el) => {
|
{assignmentsClasses.map((el) => {
|
||||||
return (
|
return (
|
||||||
<MenuItem key={el.id} value={el}>
|
<MenuItem key={el.id} value={el}>
|
||||||
{`${el.name} (${dayMapping[el.day - 1]} ${el.time} ${el.endTime})`}
|
{`${el.name} (${dayMapping[el.day]} ${el.time} ${el.endTime})`}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@ -197,36 +225,28 @@ export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => {
|
|||||||
<Select
|
<Select
|
||||||
labelId="demo-simple-select-label"
|
labelId="demo-simple-select-label"
|
||||||
id="assignments-groups"
|
id="assignments-groups"
|
||||||
// value={selectedGroups}
|
value={selectedGroup}
|
||||||
// onChange={handleSelectedGroupsChange}
|
onChange={handleGroupsChange}
|
||||||
placeholder="Wyszukaj..."
|
placeholder="Wyszukaj..."
|
||||||
style={{ width: '200px' }}
|
style={{ width: '200px' }}
|
||||||
>
|
>
|
||||||
{assignmentsGroups.map((el) => {
|
{groups.map((el: any, index: number) => {
|
||||||
return (
|
return (
|
||||||
<MenuItem key={el.id} value={el}>
|
<MenuItem key={index} value={el}>
|
||||||
{el.name}
|
{`${selectedAssignmentsClasses.name} ${el.time} ${el.endTime} ${dayMapping[el.day]}`}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Select>
|
</Select>
|
||||||
{/* <Input
|
|
||||||
placeholder={`Wyszukaj przedmioty...`}
|
|
||||||
onChange={handleChange}
|
|
||||||
value={input}
|
|
||||||
onFocus={() => {
|
|
||||||
handleShowDropdown();
|
|
||||||
}}
|
|
||||||
/> */}
|
|
||||||
<DropdownModal
|
|
||||||
handleSelectedGroupChange={handleSelectedGroupChange}
|
|
||||||
open={open}
|
|
||||||
input={input}
|
|
||||||
handleCloseDropdown={handleCloseDropdown}
|
|
||||||
selectedOption={'przedmioty'}
|
|
||||||
/>
|
|
||||||
</TransferInputStyled>
|
</TransferInputStyled>
|
||||||
</TransferReceiveStyled>
|
</TransferReceiveStyled>
|
||||||
|
<SaveButton
|
||||||
|
onClick={() => {
|
||||||
|
createExchange([selectedAssignmentsClasses.id, selectedGroup.id]);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
WYŚLIJ
|
||||||
|
</SaveButton>
|
||||||
</TransferStyled>
|
</TransferStyled>
|
||||||
</Fade>
|
</Fade>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
Loading…
Reference in New Issue
Block a user