import React, { useEffect, useState } from 'react' import ProductItem from './ProductItem' import { useMessage } from '@/hooks/useMessage' import Image from 'next/image' import dayjs from 'dayjs' import { useAxios } from '@/hooks/useAxios' import { useRecoilValue } from 'recoil' import { useRouter } from 'next/navigation' import { globalLocaleStore } from '@/store/localeAtom' import { queryStringFormatter } from '@/util/common-utils' import { sessionStore } from '@/store/commonAtom' import MainSkeleton from '../ui/MainSkeleton' export default function MainContents() { const { getMessage } = useMessage() const router = useRouter() const globalLocaleState = useRecoilValue(globalLocaleStore) const { promiseGet, get } = useAxios(globalLocaleState) const sessionState = useRecoilValue(sessionStore) //최근 물건 const [objectList, setObjectList] = useState([]) //공지사항 const [recentNoticeList, setRecentNoticeList] = useState([]) //FAQ const [recentFaqList, setRecentFaqList] = useState([]) //Sales Contact info const [businessCharger, setBusinessCharger] = useState(null) const [businessChargerMail, setBusinessChargerMail] = useState(null) useEffect(() => { fetchObjectList() fetchNoticeList() fetchFaqList() }, [sessionState]) //최근 갱신 물건목록 / Sales Contact info 정보 const fetchObjectList = async () => { try { const apiUrl = `/api/main-page/object/${sessionState?.storeId}/list` await promiseGet({ url: apiUrl, }).then((res) => { if (res.status === 200) { setObjectList(res.data.objectList) setBusinessCharger(res.data.businessCharger) setBusinessChargerMail(res.data.businessChargerMail) } else { setObjectList([]) setBusinessCharger(null) setBusinessChargerMail(null) } }) } catch (error) { console.error('MAIN API fetching error:', error) } } //공지사항 호출 const fetchNoticeList = async () => { try { const param = { schNoticeTpCd: 'QC', schNoticeClsCd: 'NOTICE', startRow: 1, endRow: 1, } const noticeApiUrl = `api/board/list?${queryStringFormatter(param)}` await promiseGet({ url: noticeApiUrl }).then((res) => { if (res.status === 200) { setRecentNoticeList(res.data.data) } else { setRecentNoticeList([]) } }) } catch (error) { console.error('NOTICE fetching error:', error) } } //FAQ 호출 const fetchFaqList = async () => { try { const param = { schNoticeTpCd: 'QC', schNoticeClsCd: 'FAQ', startRow: 1, endRow: 3, } const faqApiUrl = `api/board/list?${queryStringFormatter(param)}` await promiseGet({ url: faqApiUrl, }).then((res) => { if (res.status === 200) { setRecentFaqList(res.data.data) } else { setRecentFaqList([]) } }) } catch (error) { console.error('FAQ fetching error:', error) } } return (
{objectList.length > 0 ? (
    {objectList.map((row) => { return (
  • { if (row.objectNo.substring(0, 1) === 'R') { router.push(`/management/stuff/detail?objectNo=${row.objectNo.toString()}`) } else { router.push(`/management/stuff/tempdetail?objectNo=${row.objectNo.toString()}`) } }} >
    {dayjs(row.lastEditDatetime).format('YYYY.MM.DD HH:mm:ss')} {row.objectNo} {row.objectName} {row.saleStoreName}
  • ) })}
) : ( )}
{recentNoticeList.length > 0 ? ( <>
{dayjs(recentNoticeList[0]?.regDt).format('YYYY.MM.DD')}
{recentNoticeList[0]?.title}
{recentNoticeList[0]?.contents}
) : null}
    {recentFaqList.length > 0 ? ( <> {recentFaqList.map((row) => { return (
  • FAQ {row.noticeNo}
    {row.title}
    {dayjs(row.regDt).format('YYYY.MM.DD')}
  • ) })} ) : null}
  • react
    {(businessCharger &&
    {businessCharger}
    ) || (
    {getMessage('main.content.noBusiness')}
    )}
  • react
    {(businessChargerMail &&
    {businessChargerMail}
    ) || (
    {getMessage('main.content.noBusiness')}
    )}
) }