mocked saveBasket to backend
This commit is contained in:
parent
d6aa58fd34
commit
ffce67ab42
@ -42,10 +42,13 @@ const SaveButton = styled.div`
|
|||||||
height: 40px;
|
height: 40px;
|
||||||
background-color: red;
|
background-color: red;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
&:hover {
|
||||||
|
color: #d3d3d3;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const Rightbar = () => {
|
export const Rightbar = () => {
|
||||||
const { courses, basket } = useContext(coursesContext)!;
|
const { courses, basket, saveBasket } = useContext(coursesContext)!;
|
||||||
|
|
||||||
const getBasketGroups = () => {
|
const getBasketGroups = () => {
|
||||||
const names = basket.map(({ name }) => name);
|
const names = basket.map(({ name }) => name);
|
||||||
@ -62,7 +65,7 @@ export const Rightbar = () => {
|
|||||||
Hubert Wrzesiński<br></br>
|
Hubert Wrzesiński<br></br>
|
||||||
Semestr zimowy 2020/2021
|
Semestr zimowy 2020/2021
|
||||||
</p>
|
</p>
|
||||||
<SaveButton>SAVE</SaveButton>
|
<SaveButton onClick={saveBasket}>SAVE</SaveButton>
|
||||||
</RightbarTextStyled>
|
</RightbarTextStyled>
|
||||||
{filteredCourses.map((course, index) => (
|
{filteredCourses.map((course, index) => (
|
||||||
<CourseCard course={course} key={index} />
|
<CourseCard course={course} key={index} />
|
||||||
|
@ -8,6 +8,7 @@ interface CourseContext {
|
|||||||
addToBasket: (courses: Course) => void;
|
addToBasket: (courses: Course) => void;
|
||||||
addGroup: (group: Group, id: number) => void;
|
addGroup: (group: Group, id: number) => void;
|
||||||
deleteFromBasket: (id: number) => void;
|
deleteFromBasket: (id: number) => void;
|
||||||
|
saveBasket: () => void;
|
||||||
}
|
}
|
||||||
export const coursesContext = createContext<CourseContext | null>(null);
|
export const coursesContext = createContext<CourseContext | null>(null);
|
||||||
|
|
||||||
@ -32,12 +33,14 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
|
|||||||
|
|
||||||
const deleteFromBasket = (id: number) => setBasket(basket.filter((course) => course.id !== id));
|
const deleteFromBasket = (id: number) => setBasket(basket.filter((course) => course.id !== id));
|
||||||
|
|
||||||
useEffect(() => {
|
const saveBasket = () => {
|
||||||
console.log('BASKET');
|
// try {
|
||||||
console.log(basket);
|
// axios.post(`${process.env.REACT_APP_API_URL}/api/v1/commisions/add`);
|
||||||
}, [basket]);
|
// } catch (e) {
|
||||||
|
// console.log(e);
|
||||||
//immutability
|
// }
|
||||||
|
console.log('saving to basket');
|
||||||
|
};
|
||||||
|
|
||||||
const addGroup = (choosenGroup: Group, id: number) => {
|
const addGroup = (choosenGroup: Group, id: number) => {
|
||||||
const basketCourse = basket.filter((course) => course.id === id)[0];
|
const basketCourse = basket.filter((course) => course.id === id)[0];
|
||||||
@ -74,7 +77,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<coursesContext.Provider value={{ courses, basket, addToBasket, addGroup, deleteFromBasket }}>
|
<coursesContext.Provider value={{ courses, basket, addToBasket, addGroup, deleteFromBasket, saveBasket }}>
|
||||||
{children}
|
{children}
|
||||||
</coursesContext.Provider>
|
</coursesContext.Provider>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user