-
Notifications
You must be signed in to change notification settings - Fork 6
Feat : 링크 수정 & 삭제 기능 작업 #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
715b952
Feat: Dropdown 컴포넌트 생성
99minji 5b0e946
Merge branch 'develop' of https://github.com/codeit9-temporary/linkbr…
99minji 48dfa67
Merge branch 'develop' of https://github.com/codeit9-temporary/linkbr…
99minji a3ab47e
Merge branch 'develop' of https://github.com/codeit9-temporary/linkbr…
99minji ef4648a
Feat: - dropdown 삭제하기 DeleteLinkModal 사용
99minji 4f7619c
Feat: 링크 수정 모달 생성
99minji a614c13
Feat: 수정하기 버튼 클릭 시 EditLink 호출
99minji 8906724
Feat: 링크 수정 서버 api 생성
99minji a7baf53
Merge branch 'develop' of https://github.com/codeit9-temporary/linkbr…
99minji 9616d70
Chore: develop merge
99minji c941779
Fix: 링크 페이지에서 드롭다운 구현으로 변경
99minji b1f340f
Fix: 즐겨찾기 구현 작업 삭제
99minji 1ea09c8
Chore: 불필요한 코드 삭제
99minji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import React from "react"; | ||
|
|
||
| interface DropdownProps { | ||
| onEdit?: () => void; | ||
| openDelete?: () => void; | ||
| } | ||
|
|
||
| const Dropdown = ({ onEdit, openDelete }: DropdownProps) => { | ||
| const buttonStyle = | ||
| "block w-full py-2 text-sm hover:bg-gray200 hover:text-purple100"; | ||
|
|
||
| return ( | ||
| <div className="absolute top-[17px] right-0 flex flex-col gap-[2px] min-w-[100px] bg-white shadow-lg rounded"> | ||
| <button className={buttonStyle} onClick={onEdit}> | ||
| 수정하기 | ||
| </button> | ||
| <button className={buttonStyle} onClick={openDelete}> | ||
| 삭제하기 | ||
| </button> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Dropdown; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 안그래도 요걸 제가 안만들어놨었는데 추가해주셨군요!👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { ChangeEvent, useState } from "react"; | ||
| import { useLinkCardStore } from "@/store/useLinkCardStore"; | ||
| import ModalContainer from "./modalComponents/ModalContainer"; | ||
| import ModalInput from "./modalComponents/ModalInput"; | ||
| import useModalStore from "@/store/useModalStore"; | ||
| import SubmitButton from "../SubMitButton"; | ||
|
|
||
| const EditLink = ({ | ||
| folderName, | ||
| link, | ||
| linkId, | ||
| }: { | ||
| folderName: string; | ||
| link: string; | ||
| linkId: number; | ||
| }) => { | ||
| const [value, setValue] = useState(""); | ||
| const { closeModal } = useModalStore(); | ||
| const { updateLink } = useLinkCardStore(); | ||
|
|
||
| const handleChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
| setValue(e.target.value); | ||
| }; | ||
|
|
||
| const handleSubmit = async () => { | ||
| const body = { | ||
| url: value, | ||
| }; | ||
| if (value !== "") { | ||
| await updateLink(linkId, body); | ||
| } | ||
| closeModal(); | ||
| }; | ||
| return ( | ||
| <ModalContainer title="링크 주소 변경"> | ||
| <ModalInput | ||
| placeholder={link} | ||
| name={folderName} | ||
| value={value} | ||
| onChange={handleChange} | ||
| /> | ||
| <SubmitButton | ||
| type="button" | ||
| onClick={handleSubmit} | ||
| width="w-full" | ||
| height="h-[51px] " | ||
| color="positive" | ||
| > | ||
| 변경하기 | ||
| </SubmitButton> | ||
| </ModalContainer> | ||
| ); | ||
| }; | ||
| export default EditLink; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import axiosInstance from "@/lib/api/axiosInstanceApi"; | ||
| import { NextApiRequest, NextApiResponse } from "next"; | ||
| import { isAxiosError } from "axios"; | ||
|
|
||
| const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
| const token = req.cookies.accessToken; | ||
|
|
||
| if (!token) { | ||
| return res.status(401).json({ error: "사용자 정보를 찾을 수 없습니다." }); | ||
| } | ||
|
|
||
| const { linkId } = req.query; | ||
|
|
||
| switch (req.method) { | ||
| // 링크 삭제 | ||
| case "DELETE": | ||
| if (!linkId) { | ||
| return res | ||
| .status(400) | ||
| .json({ message: "삭제할 링크 ID가 필요합니다." }); | ||
| } | ||
|
|
||
| try { | ||
| await axiosInstance.delete(`/links/${linkId}`, { | ||
| headers: { | ||
| Authorization: `Bearer ${token}`, | ||
| }, | ||
| }); | ||
|
|
||
| return res.status(200).json({ message: "링크 삭제 성공" }); | ||
| } catch (error) { | ||
| if (isAxiosError(error) && error.response) { | ||
| const status = error.response.status; | ||
| const message = | ||
| error.response.data?.message || "알 수 없는 오류 발생"; | ||
| return res.status(status).json({ message }); | ||
| } | ||
| return res.status(500).json({ message: "서버 오류" }); | ||
| } | ||
| // 링크 수정 | ||
| case "PUT": | ||
| if (!linkId) { | ||
| return res | ||
| .status(400) | ||
| .json({ message: "업데이트할 링크 ID가 필요합니다." }); | ||
| } | ||
|
|
||
| const updateData = req.body; | ||
| if (!updateData) { | ||
| return res | ||
| .status(400) | ||
| .json({ message: "업데이트할 데이터가 필요합니다." }); | ||
| } | ||
|
|
||
| try { | ||
| await axiosInstance.put(`/links/${linkId}`, updateData, { | ||
| headers: { | ||
| Authorization: `Bearer ${token}`, | ||
| }, | ||
| }); | ||
|
|
||
| return res.status(200).json({ message: "링크 업데이트 성공" }); | ||
| } catch (error) { | ||
| if (isAxiosError(error) && error.response) { | ||
| const status = error.response.status; | ||
| const message = | ||
| error.response.data?.message || "알 수 없는 오류 발생"; | ||
| return res.status(status).json({ message }); | ||
| } | ||
| return res.status(500).json({ message: "서버 오류" }); | ||
| } | ||
|
|
||
| default: | ||
| return res.status(405).json({ message: "허용되지 않은 접근 방법" }); | ||
| } | ||
| }; | ||
|
|
||
| export default handler; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모달 파일마다 공백이 있었더라구요 😅👍