-
Notifications
You must be signed in to change notification settings - Fork 5
Feat: 알바폼 상세 스크랩(버그있음) / 카카오 공유하기 추가 #146
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
4 commits
Select commit
Hold shift + click to select a range
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
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 was deleted.
Oops, something went wrong.
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,61 @@ | ||
| "use client"; | ||
| import React, { useState } from "react"; | ||
| import { FaBookmark, FaRegBookmark } from "react-icons/fa"; | ||
| import { cn } from "@/lib/tailwindUtil"; | ||
| import axios from "axios"; | ||
| import toast from "react-hot-toast"; | ||
|
|
||
| interface ScrapBtnProps { | ||
| className?: string; | ||
| formId: number; | ||
| } | ||
|
|
||
| const ScrapBtn = ({ className = "", formId }: ScrapBtnProps) => { | ||
| const [isScraped, setIsScraped] = useState(false); | ||
|
|
||
| const toggleScrap = () => { | ||
| setIsScraped((prev) => !prev); | ||
| }; | ||
|
|
||
| const handleScrap = () => { | ||
| toggleScrap(); | ||
| if (!isScraped) { | ||
| // 스크랩 | ||
| try { | ||
| axios.post(`/api/forms/${formId}/scrap`, { formId }); | ||
| toast.success("스크랩 되었습니다."); | ||
| } catch (error) { | ||
| toggleScrap(); | ||
| } | ||
| } | ||
| if (isScraped) { | ||
| // 스크랩 취소 | ||
| try { | ||
| axios.delete(`/api/forms/${formId}/scrap`); | ||
| toast.success("스크랩이 취소되었습니다."); | ||
| } catch (error) { | ||
| toggleScrap(); | ||
| } | ||
| return; | ||
| } | ||
| }; | ||
| console.log(isScraped); | ||
|
|
||
| return ( | ||
| <button | ||
| className={cn( | ||
| "inline-flex h-12 w-12 items-center justify-center rounded-full bg-primary-orange-50 p-2 transition-colors", | ||
| className | ||
| )} | ||
| onClick={handleScrap} | ||
| > | ||
| {isScraped ? ( | ||
| <FaBookmark className={cn("text-xl text-primary-orange-300")} /> | ||
| ) : ( | ||
| <FaRegBookmark className={cn("text-xl text-primary-orange-300")} /> | ||
| )} | ||
| </button> | ||
| ); | ||
| }; | ||
|
|
||
| export default ScrapBtn; |
24 changes: 0 additions & 24 deletions
24
src/app/stories/design-system/components/buttons/BookmarkBtn.stories.tsx
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
src/app/stories/design-system/components/buttons/ScrapBtn.stories.tsx
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 ScrapBtn from "@/app/components/button/default/ScrapBtn"; | ||
| import type { Meta, StoryObj } from "@storybook/react"; | ||
|
|
||
| const meta: Meta<typeof ScrapBtn> = { | ||
| title: "Design System/Components/Button/ScrapBtn", | ||
| component: ScrapBtn, | ||
| parameters: { | ||
| layout: "centered", | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof ScrapBtn>; | ||
|
|
||
| export const Bookmarked: Story = { | ||
| args: {}, | ||
| render: (args) => { | ||
| return ( | ||
| <div> | ||
| <ScrapBtn {...args} /> | ||
| </div> | ||
| ); | ||
| }, | ||
| }; |
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,52 @@ | ||
| declare global { | ||
| interface Window { | ||
| Kakao: any; | ||
| } | ||
| } | ||
|
|
||
| export const handleShare = (templateArgs: { | ||
| title: string; | ||
| description: string; | ||
| imageUrl: string; | ||
| mobileWebUrl: string; | ||
| webUrl: string; | ||
| }) => { | ||
| if (typeof window === "undefined" || !window.Kakao) { | ||
| alert("카카오 SDK가 로드되지 않았습니다."); | ||
| return; | ||
| } | ||
|
|
||
| const { Kakao } = window; | ||
|
|
||
| if (!Kakao.isInitialized()) { | ||
| alert("카카오 SDK가 초기화되지 않았습니다."); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| Kakao.Share.sendDefault({ | ||
| objectType: "feed", // 피드 템플릿 | ||
| content: { | ||
| title: templateArgs.title, // 공유할 제목 | ||
| description: templateArgs.description, // 설명 | ||
| imageUrl: templateArgs.imageUrl, // 공유할 이미지 URL | ||
| link: { | ||
| mobileWebUrl: templateArgs.mobileWebUrl, // 모바일 웹 URL | ||
| webUrl: templateArgs.webUrl, // 웹 URL | ||
| }, | ||
| }, | ||
| buttons: [ | ||
| { | ||
| title: "자세히 보기", // 버튼 제목 | ||
| link: { | ||
| mobileWebUrl: templateArgs.mobileWebUrl, // 버튼 클릭 시 이동할 URL | ||
| webUrl: templateArgs.webUrl, // 버튼 클릭 시 이동할 URL | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
| } catch (error) { | ||
| console.error("카카오 공유 중 오류 발생:", error); | ||
| alert("공유 중 오류가 발생했습니다. 콘솔을 확인하세요."); | ||
| } | ||
| }; |
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.
👍