Skip to content

Commit

Permalink
Merge pull request #110 from kkn1125/kkn1125/fe/hotfix
Browse files Browse the repository at this point in the history
[FE][:wrench: HOTFIX]: 카드 default 제거 + recommend페이지 cart추가 예시 코드 작성
  • Loading branch information
kkn1125 authored Aug 7, 2022
2 parents d865a63 + 3f965a6 commit b4d8506
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/main/frontend/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export enum UserColumnStrings {
}

class User extends PModel implements IModel<User, UserColumn> {
private nickName: ModelStringValue = "";
private email: ModelStringValue = "";
private password: ModelStringValue = "";
private profileImg: ModelStringValue = "";
private phone: ModelStringValue = "";
private isFaceSign: ModelBooleanValue = false;
private terms: ModelBooleanValue = false;
private nickName: ModelStringValue;
private email: ModelStringValue;
private password: ModelStringValue;
private profileImg: ModelStringValue;
private phone: ModelStringValue;
private isFaceSign: ModelBooleanValue;
private terms: ModelBooleanValue;

// setter
public set(column: UserColumn, value: ModelValue) {
Expand Down
24 changes: 22 additions & 2 deletions src/main/frontend/src/pages/Diary/Recommend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import {
} from "@mui/material";
import { Box } from "@mui/system";
import axios from "axios";
import React, { useState } from "react";
import React, { useContext, useState } from "react";
import { useEffect } from "react";
import { insertCart } from "../../apis/cart";
import OverflowContent from "../../components/atoms/OverflowContent";
import { UserContext } from "../../contexts/UserProvider";
import Cart from "../../models/Cart";

interface ItemsType {
title?: string;
Expand Down Expand Up @@ -99,6 +102,7 @@ function Items({ handleClickOpen }: ItemsProps) {
function Recommend() {
// dialog 설정
const [open, setOpen] = React.useState(false);
const [user, dispatch] = useContext(UserContext);
const [scroll, setScroll] = React.useState<DialogProps["scroll"]>("paper");

const [product, setProduct] = React.useState<ItemsType>({});
Expand All @@ -116,6 +120,17 @@ function Recommend() {
setOpen(false);
};

const handleInsert = (productId: string) => {
const cart = new Cart();
cart.set('uid', user.id);
cart.set('pid', productId);
cart.set('amount', 1);
cart.set('isOrdered', false);

const formData = cart.makeFormData();
insertCart(formData);
};

const descriptionElementRef = React.useRef<HTMLElement>(null);
React.useEffect(() => {
if (open) {
Expand Down Expand Up @@ -149,7 +164,12 @@ function Recommend() {
<Button onClick={handleClose} variant='outlined'>
취소
</Button>
<Button onClick={handleClose} variant='contained'>
<Button
onClick={() => {
handleClose();
handleInsert(product.title);
}}
variant='contained'>
장바구니
</Button>
</DialogActions>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/narang/web/entity/Cart.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Cart {

private Long amount;

private Boolean isOrdered = false;
private Boolean isOrdered;

@CreatedDate
private LocalDateTime regdate;
Expand Down

0 comments on commit b4d8506

Please sign in to comment.