Skip to content

Commit

Permalink
✨ Feat: 폼데이터로 모달 커버에서 입력한 타이틀로 넘어가게 수정 #86
Browse files Browse the repository at this point in the history
  • Loading branch information
gd06070 committed Dec 9, 2024
1 parent 06a77ff commit 5190b8e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
15 changes: 13 additions & 2 deletions src/components/common/MainModalCover.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { useModalStore } from '../../stores/modalStatus';
import { useThreadsTitleStore } from '../../stores/titleStatus';
import Remix from './Remix';
import DropdownSelector from './DropdownSelector';
import SignatureImage from './SignatureImage';
import tempOptionList from '../../datas/temp-options-list.json'; // 임시 드롭다운 옵션 데이터

const MainModalCover = ({ isPlaceEdit = null }) => {
const MainModalCover = ({ isPlaceEdit = null, onTitleChange = () => {} }) => {
const { threadsTitle, setThreadsTitle } = useThreadsTitleStore();

const handleTitleChange = (event) => {
const newTitle = event.target.value;
setThreadsTitle(newTitle);
onTitleChange(newTitle);
};

const { modalStatus, modalData, toggleModal, setEditMode, setSlaveIndex } =
useModalStore((state) => state);

Expand Down Expand Up @@ -95,10 +104,12 @@ const MainModalCover = ({ isPlaceEdit = null }) => {
type="text"
id="input-thread-title"
placeholder="글타래 제목 입력..."
value={threadsTitle}
onChange={handleTitleChange}
/>
) : (
<span className="thread-title-content">
{modalData.threadTitle}
{threadsTitle}
</span>
)}
</h5>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/ThreadMissingReport.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { createMissingReportArticle } from '../api/threadApi';
import { useThreadsTitleStore } from '../stores/titleStatus';

import AsteriskTextGuide from '../components/common/AsteriskTextGuide';
import ModalInstruction from '../components/common/ModalInstruction';
Expand Down Expand Up @@ -29,6 +30,7 @@ const ThreadMissingReport = () => {
const [errorMessage, setErrorMessage] = useState('');
const [isNeutered, setIsNeutered] = useState(false);
const [hasChip, setHasChip] = useState(false);
const { threadsTitle } = useThreadsTitleStore();

const handleTypeSelect = (typeId) => {
setIsSelectedType(typeId);
Expand Down Expand Up @@ -79,7 +81,7 @@ const ThreadMissingReport = () => {
const formData = {
type: 'lost',
articleStatus: 'PUBLISHED',
title: '타이틀받아와야하는데',
title: threadsTitle,
latitude: missingAddress.coordinates.lat.toString(),
longitude: missingAddress.coordinates.lng.toString(),
description: detailExplanation,
Expand Down
4 changes: 3 additions & 1 deletion src/pages/ThreadPlace.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { createPlaceArticle } from '../api/threadApi';
import { useThreadsTitleStore } from '../stores/titleStatus';

import ModalInstruction from '../components/common/ModalInstruction';
import ModalSectionTitle from '../components/common/ModalSectionTitle';
Expand Down Expand Up @@ -27,6 +28,7 @@ const ThreadPlace = () => {
// longitude: latestLocation.lng,
});
const [errorMessage, setErrorMessage] = useState('');
const { threadsTitle } = useThreadsTitleStore();

const handleAddressChange = (info) => {
setAddressInfo(info);
Expand Down Expand Up @@ -63,7 +65,7 @@ const ThreadPlace = () => {
const formData = {
type: 'place',
articleStatus: 'PUBLISHED',
title: '테스트스테',
title: threadsTitle,
latitude: latestLocation.lat || 0, // 위도
longitude: latestLocation.lng || 0, // 경도
description: introduce,
Expand Down
4 changes: 3 additions & 1 deletion src/pages/ThreadRescue.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from 'react';
import { createRescueArticle } from '../api/threadApi';
import { useThreadsTitleStore } from '../stores/titleStatus';

import ModalInstruction from '../components/common/ModalInstruction';
import ModalSectionTitle from '../components/common/ModalSectionTitle';
Expand All @@ -16,6 +17,7 @@ const ThreadRescue = () => {
const [dateTime, setDateTime] = useState('');
const [situation, setSituation] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const { threadsTitle } = useThreadsTitleStore();

const mallangTypes = [
{ id: 'DOG', label: '강아지' },
Expand Down Expand Up @@ -54,7 +56,7 @@ const ThreadRescue = () => {
const formData = {
type: 'rescue',
articleStatus: 'PUBLISHED', // 필요한 상태값
title: '꽁꽁 얼어붙은 한강 위로 고양이가 걸어다닙니다', // 제목
title: threadsTitle, // 제목
latitude: addressInfo.coordinates.lat.toString(), // 위도
longitude: addressInfo.coordinates.lng.toString(), // 경도
description: situation, // 상황 설명
Expand Down
6 changes: 6 additions & 0 deletions src/stores/titleStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { create } from 'zustand';

export const useThreadsTitleStore = create((set) => ({
threadsTitle: '',
setThreadsTitle: (title) => set({ threadsTitle: title }),
}));

0 comments on commit 5190b8e

Please sign in to comment.