From e5d0ef6b95dc8551ad713e7d1ff63c42a9783717 Mon Sep 17 00:00:00 2001
From: Devicii <62472550+asroq1@users.noreply.github.com>
Date: Tue, 16 Jan 2024 20:11:31 +0900
Subject: [PATCH] Fix : Edit LinkForm Component
---
src/app/showcase/edit/page.tsx | 5 +-
.../showcase/edit/panel/ShowcaseEditor.tsx | 76 +++++++++------
.../edit/panel/formPanel/FormUIEditor.tsx | 10 +-
.../edit/panel/formPanel/LinkForm.tsx | 94 +++++++++----------
src/app/showcase/edit/panel/test.style.ts | 7 ++
src/types/IShowcaseEdit.ts | 4 +-
6 files changed, 112 insertions(+), 84 deletions(-)
create mode 100644 src/app/showcase/edit/panel/test.style.ts
diff --git a/src/app/showcase/edit/page.tsx b/src/app/showcase/edit/page.tsx
index 638871900..9d15ca2de 100644
--- a/src/app/showcase/edit/page.tsx
+++ b/src/app/showcase/edit/page.tsx
@@ -35,8 +35,9 @@ const mockData: IShowcaseEditorFields = {
isLeader: false,
},
{ nickname: '이순신', role: '백엔드 개발자', image: '', isLeader: false },
+ { nickname: '이순신', role: '리더', image: '', isLeader: false },
],
- links: ['www.example1.com', 'www.example2.com'],
+ links: [{ linkName: '깃허브', linkUrl: '이름없음', id: 0 }],
}
const ShowCaseEditPage = () => {
@@ -52,7 +53,7 @@ const ShowCaseEditPage = () => {
// if (error) return
에러가 발생했습니다.
return (
-
+
)
diff --git a/src/app/showcase/edit/panel/ShowcaseEditor.tsx b/src/app/showcase/edit/panel/ShowcaseEditor.tsx
index aefaceddb..5bdfe87b7 100644
--- a/src/app/showcase/edit/panel/ShowcaseEditor.tsx
+++ b/src/app/showcase/edit/panel/ShowcaseEditor.tsx
@@ -6,7 +6,6 @@ import ImageInput from './formPanel/ImageInput'
import TeamName from './formPanel/TeamName'
import SkillInput from './formPanel/SkillInput'
import LinkForm from './formPanel/LinkForm'
-// import FormUIEditor from '../panel/formPanel/FormUIEditor'
import useShowCaseState from '@/states/useShowCaseState'
import useToast from '@/hook/useToast'
import { redirect } from 'next/navigation'
@@ -16,14 +15,17 @@ import useAxiosWithAuth from '@/api/config'
import StartEndDateViewer from './formPanel/StartEndDateViewer'
import TeamMembers from './formPanel/TeamMembers'
import dynamic from 'next/dynamic'
-const DynamicEditor = dynamic(() => import('../panel/formPanel/FormUIEditor'), {
- ssr: false,
-})
+import * as style from './test.style'
+import { IUserProfileLink } from '@/types/IUserProfile'
interface IShowcaseEditorProps {
data: IShowcaseEditorFields // IShowcase 타입을 import 해야 합니다.
}
+const DynamicEditor = dynamic(() => import('../panel/formPanel/FormUIEditor'), {
+ ssr: false,
+})
+
const ShowcaseEditor = ({ data }: IShowcaseEditorProps) => {
const axiosWithAuth = useAxiosWithAuth()
const [image, setImage] = useState([])
@@ -33,33 +35,37 @@ const ShowcaseEditor = ({ data }: IShowcaseEditorProps) => {
const [errorMessages, setErrorMessages] = useState('')
const { CuToast, isOpen, openToast, closeToast } = useToast()
const { isOpen: alertOpen, closeModal, openModal } = useModal()
- // const [alertOpen, setAlertOpen] = useState(false)
- // 1. 아무것도 안 보내면 기본 이미지 적용. 그러나 저장 이전에 한 번 더 물음
+ const useLinks = (initValue: IUserProfileLink[]) => {
+ const [links, setLinks] = useState(initValue)
+
+ const addLink = (linkName: string, linkUrl: string) => {
+ const newLink = { linkName, linkUrl, id: links.length }
+ setLinks([...links, newLink])
+ }
+
+ const changeLinkName = (id: number, content: string) => {
+ // links[id].linkName = content
+ setLinks(
+ links.map((link) =>
+ link.id === id ? { ...link, linkName: content } : link,
+ ),
+ )
+ }
- // const defaultValues: IShowcaseEditorFields = {
- // image: null,
- // tags: data?.skills ? data.skills : [],
- // startDate: data?.start ? data.start : '',
- // endDate: data?.end ? data.end : '',
- // links: [{ id: 0, linkName: '', linkUrl: '' }],
- // content: '',
- // members: data?.member,
- // }
- // const { control, setValue, watch } = useForm({
- // defaultValues: defaultValues,
- // })
+ const changeUrl = (id: number, content: string) => {
+ setLinks(
+ links.map((link) =>
+ link.id === id ? { ...link, linkUrl: content } : link,
+ ),
+ )
+ }
- // const { fields, append, remove } = useFieldArray({
- // control,
- // name: 'links',
- // })
+ return { links, addLink, changeLinkName, changeUrl }
+ }
+ const { links, addLink, changeLinkName, changeUrl } = useLinks([])
const submitHandler = async () => {
- // if (!previewImage) {
- // openModal()
- // return
- // }
try {
const response = await axiosWithAuth.post(
`${process.env.NEXT_PUBLIC_API_URL}/api/v1/showcase/write`,
@@ -67,12 +73,12 @@ const ShowcaseEditor = ({ data }: IShowcaseEditorProps) => {
image: 'previewImage',
content: 'content',
teamId: 'value3',
+ links: links,
},
)
console.log(`/api/showcase response : ${response}`)
redirect(`/showcase/${response.data.get('id')}`) // next 13에서 redirect 하는 법
} catch (error: any) {
- console.log(`/api/showcase error ${error}`)
if (error.response) {
switch (error.response.status) {
case 400:
@@ -98,15 +104,16 @@ const ShowcaseEditor = ({ data }: IShowcaseEditorProps) => {
setErrorMessages('요청을 설정하는 중에 에러가 발생했습니다.')
}
}
+ console.log('링크', links[0].linkName, links[0].linkUrl)
alert(
- `Image ${image}, Coverimage : ${previewImage}, content : ${text}, teamId : ${content},`,
+ `links : ${links} ${image} Coverimage : ${previewImage}, content : ${text}, teamId : ${content},`,
)
}
// if (isLoading) return 로딩중
// if (error) return 에러
return (
-