Skip to content

Commit

Permalink
#61 feat vehicle CRUD Delete function added
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonih1020 committed Sep 13, 2022
1 parent 1c40d93 commit 185fdae
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions tiger-fe/src/components/owner/OwnerItem.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React from "react";
import { Link, useNavigate, useParams } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import styled from "styled-components";
import VehicleModify from "./VehicleModify";
import axios from "axios";
import { __registeredItemList } from "../../redux/modules/ownerItemListSlice";
import { useDispatch } from "react-redux";

const OwnerItem = ({ list, category, vid }) => {
// console.log(vId);
const serverApi = process.env.REACT_APP_SERVER;

const dispatch = useDispatch();

const onClick = () => {
console.log("눌림");
};
Expand All @@ -14,6 +19,27 @@ const OwnerItem = ({ list, category, vid }) => {
navigate(`/owner/${vid}/modi`);
};

const vId = vid;
// console.log(vId);

const deleteHandler = async () => {
const userToken = localStorage.getItem("userToken");
const refreshToken = localStorage.getItem("refreshToken");
const headers = {
"Content-Type": "application/json",
Authorization: userToken,
RefreshToken: refreshToken,
};
const response = await axios.delete(
serverApi + `/vehicle/management/${vId}`,
{
headers: headers,
}
);
console.log(response);
dispatch(__registeredItemList());
};

return (
<>
{category === "Registration" ? (
Expand All @@ -34,7 +60,9 @@ const OwnerItem = ({ list, category, vid }) => {
<span className="modify" onClick={goUpdate}>
수정
</span>
<span className="delete">삭제</span>
<span className="delete" onClick={deleteHandler}>
삭제
</span>
</div>
</div>
</StOwnerItem>
Expand Down

0 comments on commit 185fdae

Please sign in to comment.