Skip to content

Commit cf96e56

Browse files
committed
feat: MyInquiriesWrapper 추가 및 스크롤 기능 구현, Inquiry 컴포넌트 수정
1 parent cae7c46 commit cf96e56

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

src/components/user/mypage/activityLog/inquiries/Inquiries.styled.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export const InquiriesTableHeaderState = styled.div`
4444
text-align: center;
4545
`;
4646

47+
export const MyInquiriesWrapper = styled.div<{ $headHeight: number }>`
48+
scroll-margin-top: ${({ $headHeight }) => $headHeight + 10}px;
49+
`;
50+
4751
export const InquiriesWrapper = styled.div`
4852
margin-top: 1rem;
4953
display: flex;

src/components/user/mypage/activityLog/inquiries/Inquiries.tsx

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
1-
import { useParams } from 'react-router-dom';
1+
import { useLocation, useParams } from 'react-router-dom';
22
import useGetUserActivity from '../../../../../hooks/admin/useGetAllUserActivity';
33
import ContentBorder from '../../../../common/contentBorder/ContentBorder';
44
import NoContent from '../../../../common/noContent/NoContent';
55
import Spinner from '../../Spinner';
66
import * as S from './Inquiries.styled';
77
import Inquiry from './inquiry/Inquiry';
88
import type { MyInquiries } from '../../../../../models/activityLog';
9+
import { useLayoutEffect, useRef, useState } from 'react';
910

1011
export default function Inquiries() {
1112
const { userId } = useParams();
13+
const { state } = useLocation();
14+
const { id } = state || {};
1215
const { userActivityData, isLoading } = useGetUserActivity(
1316
Number(userId),
1417
'inquiries'
1518
);
19+
const headRef = useRef<HTMLDivElement>(null);
20+
const inquiriesRef = useRef<(HTMLDivElement | null)[]>([]);
21+
const [headHeight, setHeadHeight] = useState<number>(0);
22+
23+
useLayoutEffect(() => {
24+
if (!id || !headRef?.current) return;
25+
const height = headRef.current.offsetHeight;
26+
setHeadHeight(height);
27+
const idx = userActivityData?.findIndex((item) => item.id == id);
28+
const targetRef = typeof idx === 'number' ? inquiriesRef.current[idx] : '';
29+
if (inquiriesRef?.current && targetRef) {
30+
targetRef.scrollIntoView({ behavior: 'smooth', block: 'start' });
31+
}
32+
}, [userActivityData, id, headHeight]);
1633

1734
if (isLoading) {
1835
return (
@@ -36,7 +53,7 @@ export default function Inquiries() {
3653
return (
3754
<S.container>
3855
<S.InquiriesContainer>
39-
<S.InquiriesTableHeadContainer>
56+
<S.InquiriesTableHeadContainer ref={headRef}>
4057
<S.InquiriesTableHeadWrapper>
4158
<S.InquiriesTableHeaderNo>No</S.InquiriesTableHeaderNo>
4259
<S.InquiriesTableHeaderCategory>
@@ -49,11 +66,13 @@ export default function Inquiries() {
4966
</S.InquiriesTableHeadContainer>
5067
<S.InquiriesWrapper>
5168
{myInquiriesData.map((list, index) => (
52-
<Inquiry
69+
<S.MyInquiriesWrapper
70+
ref={(el) => (inquiriesRef.current[index] = el)}
5371
key={`${index}-${list.title}`}
54-
list={list}
55-
no={myInquiriesData.length - index}
56-
/>
72+
$headHeight={headHeight}
73+
>
74+
<Inquiry list={list} no={myInquiriesData.length - index} />
75+
</S.MyInquiriesWrapper>
5776
))}
5877
</S.InquiriesWrapper>
5978
</S.InquiriesContainer>

src/components/user/mypage/activityLog/inquiries/inquiry/Inquiry.styled.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export const InquiryStateSpan = styled.span<{ $isCompletedAnswer: boolean }>`
3434
$isCompletedAnswer &&
3535
css`
3636
background: ${({ theme }) => theme.color.navy};
37-
border-radius: ${({ theme }) => theme.borderRadius.small};
38-
padding: 0.2rem;
37+
border-radius: ${({ theme }) => theme.borderRadius.large};
38+
padding: 0.2rem 0.5rem;
3939
`}
4040
`;
4141

src/components/user/mypage/activityLog/inquiries/inquiry/Inquiry.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { useRef, useState } from 'react';
1+
import { useEffect, useRef, useState } from 'react';
22
import type { MyInquiries } from '../../../../../../models/activityLog';
33
import * as S from './Inquiry.styled';
44
import { My_INQUIRIES_MESSAGE } from '../../../../../../constants/user/customerService';
55
import ContentBorder from '../../../../../common/contentBorder/ContentBorder';
66
import { ChevronRightIcon } from '@heroicons/react/24/outline';
7+
import { useLocation } from 'react-router-dom';
78

89
interface InquiryProps {
910
list: MyInquiries;
@@ -16,26 +17,28 @@ interface IsImageOpen {
1617
}
1718

1819
export default function Inquiry({ list, no }: InquiryProps) {
20+
const { state } = useLocation();
21+
const { id } = state || {};
1922
const [isOpen, setIsOpen] = useState<boolean>(false);
2023
const [isImageOpen, setIsImageOpen] = useState<IsImageOpen>({
2124
isImageOpen: false,
2225
url: '',
2326
});
2427
const answer = list.answer || '';
25-
const answerRef = useRef<HTMLTextAreaElement>(null);
28+
const divRef = useRef<HTMLDivElement>(null);
2629

27-
const handleChangeAnswerRef = () => {
28-
if (answerRef && answerRef.current) {
29-
answerRef.current.style.height = 'auto';
30-
answerRef.current.style.height = `${answerRef.current.scrollHeight}px`;
30+
useEffect(() => {
31+
if (list.id === id) {
32+
setIsOpen(true);
3133
}
32-
};
34+
}, [list, id, setIsOpen]);
3335

3436
return (
35-
<S.Container>
37+
<S.Container ref={divRef}>
3638
<S.InquiryTitleWrapper
3739
type='button'
3840
onClick={() => setIsOpen((prev) => !prev)}
41+
data-id={list.id}
3942
>
4043
<S.InquiryNumber>{no}</S.InquiryNumber>
4144
<S.InquiryCategory>{`[${list.category}]`}</S.InquiryCategory>

src/components/user/mypage/notifications/all/All.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export default function All() {
7171
{list.alarmFilterId !== 5 ? (
7272
<Link
7373
to={linkUrl(list.routingId, list.alarmFilterId)}
74+
state={list.alarmFilterId === 4 && { id: list.routingId }}
7475
onClick={() => patchAlarm(list.id)}
7576
>
7677
<S.SpanNotification

0 commit comments

Comments
 (0)