Skip to content

Commit

Permalink
Merge pull request #91 from next-petree/feat_login
Browse files Browse the repository at this point in the history
Feat login
  • Loading branch information
ChanghyeonO authored Jan 15, 2024
2 parents 6c7d3c9 + 05ba8a1 commit 3425965
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 148 deletions.
2 changes: 1 addition & 1 deletion src/api/axiosInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ instance.interceptors.request.use(

instance.interceptors.response.use(
response => {
console.log("api ์š”์ฒญ ์‘๋‹ต :", response);
// console.log("api ์š”์ฒญ ์‘๋‹ต :", response);
return response;
},
error => {
Expand Down
1 change: 1 addition & 0 deletions src/component/DaumFindAddress/DaumFindAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const DaumFindAddress = () => {
<Modal
isOpen={isOpen}
onRequestClose={closeModal}
shouldCloseOnOverlayClick={true}
ariaHideApp={false}
className="ReactModal__Content"
overlayClassName="ReactModal__Overlay"
Expand Down
11 changes: 6 additions & 5 deletions src/component/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { useState, useCallback } from 'react';
import { useState, useCallback } from "react";

const useModal = () => {
const [isModalVisible, setIsModalVisible] = useState(false);
const [modalContent, setModalContent] = useState('');
const [modalContent, setModalContent] = useState("");

const showModal = useCallback((content: any) => {
const showModal = useCallback((content: any = "") => {
// ๊ธฐ๋ณธ๊ฐ’ ์„ค์ •
setIsModalVisible(true);
setModalContent(content);
document.body.style.overflow = 'hidden'; // ๋ชจ๋‹ฌ์ด ์—ด๋ ธ์„ ๋•Œ ๋’ท๋ฐฐ๊ฒฝ ์Šคํฌ๋กค ๋ง‰๊ธฐ
document.body.style.overflow = "hidden";
}, []);

const hideModal = useCallback(() => {
setIsModalVisible(false);
document.body.style.overflow = 'auto'; // ๋ชจ๋‹ฌ์ด ๋‹ซํ˜”์„ ๋•Œ ๋’ท๋ฐฐ๊ฒฝ ์Šคํฌ๋กค ํ—ˆ์šฉ
document.body.style.overflow = "auto";
}, []);

return { isModalVisible, showModal, hideModal, modalContent };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { useState, useMemo, useEffect } from "react";
import { useSelector } from "react-redux";
import { selectSearchResultSlice } from "../../../../../redux/SearchResult/SearchResultSlice";
import { selectSuccessResultSlice } from "../../../../../redux/SuccessResult/SuccessResultSlice";
import { styled } from "styled-components";
import { get } from "../../../../../api/api";
import { TitleWrap, Title, SubTitle, PageNationWrap } from "./RequestListStyle";
Expand Down Expand Up @@ -54,14 +57,23 @@ type ApiResponse = {
};

const RequestListContainer = () => {
const [currentPage, setCurrentPage] = useState(1); // ํ˜„์žฌ ํŽ˜์ด์ง€ ์ƒํƒœ
const [currentPage, setCurrentPage] = useState(1);
const [matchings, setMatchings] = useState<MatchingDataType[]>([]);
const [totalPages, setTotalPages] = useState(0);

const { select, inputValue } = useSelector(selectSearchResultSlice);
const apiCallCount = useSelector(selectSuccessResultSlice);

const fetchMatchingList = async (page: number) => {
let url = `/me/matchings?page=${page - 1}`;

if (select !== "์ „์ฒด") {
const searchType = select === "๊ฒฌ์ข…" ? "type" : "name";
url += `&searchType=${searchType}&keyword=${inputValue}`;
}

try {
const response = await get<ApiResponse>("/me/matchings");
console.log("API ์‘๋‹ต ๋ฐ์ดํ„ฐ:", response.data.data.totalPages);
const response = await get<ApiResponse>(url);
setTotalPages(response.data.data.totalPages);
setMatchings(response.data.data.content);
} catch (error) {
Expand All @@ -71,9 +83,8 @@ const RequestListContainer = () => {

useEffect(() => {
fetchMatchingList(currentPage);
}, [currentPage]);
}, [currentPage, select, inputValue, apiCallCount]);

// ๋ธŒ๋ฆฌ๋” ๊ฐ€๋ฐ์ดํ„ฐ!!!!!!!!!!!!!!!!!!
const BreederheaderData: BreederColumn[] = [
{ accessor: "name", Header: "๋ถ„์–‘ํฌ๋ง์ž" },
{ accessor: "breed", Header: "๊ฐ•์•„์ง€(๊ฒฌ์ข…๋ช…)" },
Expand All @@ -82,7 +93,6 @@ const RequestListContainer = () => {
];
const BreederHeaders = useMemo(() => BreederheaderData, []);

// ์ž…์–‘์ž ๊ฐ€๋ฐ์ดํ„ฐ!!!!!!!!!!!!!!!!!
const AdopterheaderData: AdopterColumn[] = [
{ accessor: "breeder", Header: "๋ธŒ๋ฆฌ๋”" },
{ accessor: "breed", Header: "๊ฐ•์•„์ง€(๊ฒฌ์ข…๋ช…)" },
Expand All @@ -94,6 +104,7 @@ const RequestListContainer = () => {

const BreederItems = useMemo(() => {
return matchings.map(matching => ({
id: matching.matchingId,
name: matching.adopterNickname,
breed: matching.dogTypeName,
bday: matching.submitDate,
Expand Down Expand Up @@ -143,8 +154,8 @@ const RequestListContainer = () => {
disabled={currentPage === 1}
style={{
margin: "0 5px",
padding: "5px 10px",
border: "1px solid #ddd",
padding: "8px 13px",
border: "none",
borderRadius: "8px",
backgroundColor: currentPage === 1 ? "#e0e0e0" : "#f0f0f0",
cursor: currentPage === 1 ? "not-allowed" : "pointer",
Expand All @@ -162,11 +173,12 @@ const RequestListContainer = () => {
disabled={currentPage === i}
style={{
margin: "0 5px",
padding: "5px 10px",
border: "1px solid #ddd",
backgroundColor: currentPage === i ? "#e0e0e0" : "#4ec1bf",
color: currentPage === i ? "black" : "white",
padding: "8px 13px",
border: "none",
backgroundColor: currentPage === i ? "#4ec1bf" : "#f0f0f0",
color: currentPage === i ? "white" : "black",
borderRadius: "8px",
cursor: "pointer",
}}
>
{i}
Expand All @@ -181,8 +193,8 @@ const RequestListContainer = () => {
disabled={currentPage === totalPages}
style={{
margin: "0 5px",
padding: "5px 10px",
border: "1px solid #fff",
padding: "8px 13px",
border: "none",
borderRadius: "8px",
backgroundColor: currentPage === totalPages ? "#e0e0e0" : "#f0f0f0",
cursor: currentPage === totalPages ? "not-allowed" : "pointer",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,76 +1,69 @@
import { useState } from "react";
import { ChangeEvent, useState } from "react";
import { useDispatch } from "react-redux";
import {
setSelect,
setInputValue,
} from "../../../../../../redux/SearchResult/SearchResultSlice";
import {
SearchWrap,
DropDown,
Input,
// Button,
DisNone,
DropDownWrap,
Selected,
} from "./Style1";
import arrowDown from "../../../../../../assets/images/arrowDown.png";
import Button from "../../Button/Button";
export default function SearchComp() {
const dispatch = useDispatch();
const [isOpen, setIsOpen] = useState(false);
const [inputValue, setInputValue] = useState("๋‚ด์—ญ์„ ๊ฒ€์ƒ‰ํ•˜์„ธ์š”");
const [select, setSelect] = useState("ํ•ญ๋ชฉ์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”");
const handleInputChange = (event: any) => {
const value = event.target.value;
if (value !== "๋‚ด์—ญ์„ ๊ฒ€์ƒ‰ํ•˜์„ธ์š”") {
setInputValue(value);
}
const [localSelect, setLocalSelect] = useState("์ „์ฒด");
const [localInputValue, setLocalInputValue] = useState("");

const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
setLocalInputValue(event.target.value);
};
const handleInputFocus = (event: any) => {

const handleInputFocus = (event: ChangeEvent<HTMLInputElement>) => {
if (event.target.value === "๋‚ด์—ญ์„ ๊ฒ€์ƒ‰ํ•˜์„ธ์š”") {
setInputValue("");
setLocalInputValue("");
}
};

const selectItem = (item: string) => {
setLocalSelect(item);
setIsOpen(false);
};

const DropOpen = () => {
if (isOpen === false) {
setIsOpen(true);
} else {
setIsOpen(false);
}
};

const getValue = () => {
console.log(`์„ ํƒ๋œ ํ•ญ๋ชฉ: ${select}, ๊ฒ€์ƒ‰์–ด: ${inputValue}`);
dispatch(setSelect(localSelect));
dispatch(setInputValue(localInputValue));
};

return (
<SearchWrap>
<DropDown>
<Selected onClick={DropOpen}>
<div>{select}</div> {/* ์ƒํƒœ ๋ณ€์ˆ˜ select์˜ ๊ฐ’์„ ํ‘œ์‹œ */}
<div>{localSelect}</div>
<img src={arrowDown} />
</Selected>
{isOpen ? (
<DropDownWrap>
<div
className="sel"
onClick={() => {
setSelect("์ „์ฒด");
setIsOpen(false);
}}
>
<div className="sel" onClick={() => selectItem("์ „์ฒด")}>
์ „์ฒด
</div>
<div
className="sel"
onClick={() => {
setSelect("๊ฒฌ์ข…");
setIsOpen(false);
}}
>
<div className="sel" onClick={() => selectItem("๊ฒฌ์ข…")}>
๊ฒฌ์ข…
</div>
<div
className="sel"
onClick={() => {
setSelect("๊ฐ•์•„์ง€ ์ด๋ฆ„");
setIsOpen(false);
}}
>
<div className="sel" onClick={() => selectItem("๊ฐ•์•„์ง€ ์ด๋ฆ„")}>
๊ฐ•์•„์ง€ ์ด๋ฆ„
</div>
</DropDownWrap>
Expand All @@ -80,10 +73,10 @@ export default function SearchComp() {
</DropDown>
<Input
type="text"
value={inputValue}
value={localInputValue}
onChange={handleInputChange}
onFocus={handleInputFocus}
></Input>
/>
<Button
bgcolor={"#4EC1BF"}
buttonwidth={"100px"}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
import React, { useState } from "react";
import { get } from "../../../../../../api/api";
import {
Td,
DetailButton,
Expand All @@ -13,82 +14,88 @@ import {
Gender,
BDay,
AnswerWrap,
AnswerInput,
AnswerTextBox,
Question,

// AnswerLength,
CountSpan,
} from "./Style1";
import useModal from "../../../../../Modal/Modal";
import DogImg from "../../../../../../assets/images/temporaryImg.png";
import CheckModal from "../CheckModal/CheckModal";

const RowModal = ({
index,
breed,
bday,
name,
}: {
index: number;
breed: string;
bday: string;
type ModalDataType = {
imgUrl: string;
name: string;
}) => {
breedType: string;
gender: string;
birthDate: string;
nurturingEnv: string;
parentExp: string;
};

type ApiResponse = {
status: string;
data: {
body: {
data: ModalDataType;
};
};
};

const RowModal = ({ matchingId }: { matchingId: number }) => {
const [modalData, setModalData] = useState<ModalDataType | null>(null);
const { isModalVisible, showModal, hideModal } = useModal();

const [inputValue1, setInputValue1] = useState(
"๋ฐ˜๋ ค๊ฒฌ์„ ์ข‹์•„ํ•˜๋Š” ์˜ˆ๋น„ ๋ถ„์–‘์ž์ž…๋‹ˆ๋‹ค. ํ˜„์žฌ ๊ฐ•์•„์ง€ 2๋งˆ๋ฆฌ๋ฅผ ํ‚ค์šฐ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ํŠนํžˆ ํฌ๋ฉ”๋ผ๋‹ˆ์•ˆ์„ ์ข‹์•„ํ•˜๋Š” ๋งˆ์Œ์— ์‹ ์ฒญํ•˜๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.",
);
const [inputValue2, setInputValue2] = useState(
"๋ฐ˜๋ ค๊ฒฌ์„ ๋งˆ์น˜ ์•„์ด์ฒ˜๋Ÿผ ์•„๋ผ๊ณ  ๋ณด์‚ดํ”ผ๊ฒ ์Šต๋‹ˆ๋‹ค. ๋งˆ์Œ์œผ๋กœ ๋‚˜์€ ์•„์ด๋ผ๋Š” ๋งˆ์Œ์œผ๋กœ ์•„ํ”Œ๋•Œ๋„ ํ•œ๊ฒฐ๊ฐ™์ด ํ‚ค์šธ๊ฒŒ์š”~!๋ฐ˜๋ ค๊ฒฌ์„ ๋งˆ์น˜ ์•„์ด์ฒ˜๋Ÿผ ์•„๋ผ๊ณ  ๋ณด์‚ดํ”ผ๊ฒ ์Šต๋‹ˆ๋‹ค. ๋งˆ์Œ์œผ๋กœ ๋‚˜์€ ์•„์ด๋ผ๋Š” ๋งˆ์Œ์œผ๋กœ ์•„ํ”Œ๋•Œ๋„ ํ•œ๊ฒฐ๊ฐ™์ด ํ‚ค์šธ๊ฒŒ์š”~!",
);
const [inputCount1, setInputCount1] = useState(0);
const [inputCount2, setInputCount2] = useState(0);
const fetchAndShowModal = async () => {
try {
const response = await get<ApiResponse>(`/me/matchings/${matchingId}`);
setModalData(response.data.data.body.data);
showModal();
} catch (error) {
console.error("๋งค์นญ ์ƒ์„ธ ์กฐํšŒ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ:", error);
}
};

const dogName = breed.match(/(.+)(?=\()/g)?.[0] || "";
const typeofdog = breed.match(/(?<=\().+?(?=\))/g)?.[0] || "";
useEffect(() => {
setInputCount1(inputValue1.length);
setInputCount2(inputValue2.length);
}, [inputValue1, inputValue2]);
return (
<Td>
<DetailButton onClick={showModal}>์ƒ์„ธ๋ณด๊ธฐ</DetailButton>
<DetailButton onClick={fetchAndShowModal}>์ƒ์„ธ๋ณด๊ธฐ</DetailButton>
{isModalVisible && (
<ModalWrap onClick={hideModal}>
<Modal onClick={e => e.stopPropagation()}>
<Title>๋ถ„์–‘ ์‹ ์ฒญ์„œ</Title>
<InfoWrap>
<Img src={DogImg}></Img>
<Img src={modalData?.imgUrl}></Img>
<DetailInfoWrap>
<DogName>{dogName}</DogName>
<DogName>{modalData?.name}</DogName>
<hr />
<BreedDog>๊ฒฌ์ข… : {typeofdog}</BreedDog>
<Gender>์„ฑ๋ณ„ : ์ˆ˜์ปท</Gender>
<BDay>์ถœ์ƒ์ผ : {bday}</BDay>
<BreedDog>๊ฒฌ์ข… : {modalData?.breedType}</BreedDog>
<Gender>์„ฑ๋ณ„ : {modalData?.gender}</Gender>
<BDay>์ถœ์ƒ์ผ : {modalData?.birthDate}</BDay>
<hr />
</DetailInfoWrap>
</InfoWrap>
<AnswerWrap>
<Question>
1. ๋ฐ˜๋ ค๋™๋ฌผ์„ ๋ถ„์–‘ํ•˜๋ ค๋Š” ์‚ฌ์œ ์— ๋Œ€ํ•ด ์ž‘์„ฑํ•˜์„ธ์š”.
</Question>
<AnswerInput>
{inputValue1}
<CountSpan>{inputCount1}/2000</CountSpan>
</AnswerInput>
<AnswerTextBox>
{modalData?.nurturingEnv}
<CountSpan>{modalData?.nurturingEnv.length}/2000</CountSpan>
</AnswerTextBox>
</AnswerWrap>
<AnswerWrap>
<Question>
2. ํ•ด๋‹น ๊ฒฌ์ข…์„ ๋ถ„์–‘ํ•˜๋Š” ๊ฒƒ์— ์žˆ์–ด ์ž์‹ ์˜ ๋งˆ์Œ๊ฐ€์ง์„
์ž‘์„ฑํ•ด์ฃผ์„ธ์š”.
</Question>
<AnswerInput>
{inputValue2}
<CountSpan>{inputCount2}/2000</CountSpan>
</AnswerInput>
<AnswerTextBox>
{modalData?.parentExp}
<CountSpan>{modalData?.parentExp.length}/2000</CountSpan>
</AnswerTextBox>
</AnswerWrap>
<CheckModal setHideModal={hideModal} name={name} />
<CheckModal
setHideModal={hideModal}
name={modalData?.name || ""}
matchingId={matchingId}
/>
</Modal>
</ModalWrap>
)}
Expand Down
Loading

0 comments on commit 3425965

Please sign in to comment.