0527 TIL

๊น€ํ˜•์„ยท2022๋…„ 5์›” 29์ผ
0

wanted-POB

๋ชฉ๋ก ๋ณด๊ธฐ
18/26

๐Ÿ’ก์ƒˆ๋กœ ๋ฐฐ์šด ๋‚ด์šฉ

๊ฒ€์ƒ‰๊ฒฐ๊ณผ๋ฅผ ํ…Œ์ด๋ธ”๋กœ ๋‚˜ํƒ€๋‚ด์ฃผ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ž‘์„ฑ์ค‘ filter์— ์—ฌ๋Ÿฌ ์กฐ๊ฑด์„ ์ ์šฉ์‹œ์ผœ์„œ ๊ฐ€๋…์„ฑ ์ข‹๊ฒŒ ์‚ฌ์šฉํ•  ์ˆœ ์—†์„๊นŒ ๋ผ๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๊ณ 
์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ๋‹ค.

์‚ฌ์‹ค ์ด๋ ‡๊ฒŒ ์จ๋„๋˜๋Š”๊ฑด์ง€ ๋ชจ๋ฅด๊ฒ ์–ด์„œ ์ฝ”์น˜๋‹˜๊ป˜ ํ•œ๋ฒˆ ์—ฌ์ญค๋ด์•ผํ•  ๊ฒƒ ๊ฐ™๋‹ค ์•ˆํ‹ฐํŒจํ„ด์ด๊ฑฐ๋‚˜ ๊ตฌ๋ฆฐ ์ฝ”๋“œ๋ผ๋ฉด ๋” ๋‚˜์€ ์ฝ”๋“œ๋กœ ๋ฐœ์ „ ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋„๋ก

Filter์— ์—ฌ๋Ÿฌ์กฐ๊ฑด ์ ์šฉ

const UserTable = () => {
  const searchUserInfo = useRecoilValue(searchedUserInfo)

  const filterSearchUser = (data: ISearchedUser) => {
    // ๋ชจ๋“  ๊ฒ€์ƒ‰์–ด ์ž…๋ ฅ์ด ์•ˆ๋์„ ๊ฒฝ์šฐ ๋นˆ๋ฐฐ์—ด ๋ฆฌํ„ด
    if (data.userID === '' && data.userNumber === 0 && data.date.start === '' && data.date.end === '') return []

    const matchId = (targetId: string) => {
      const { userID: idKeyword } = data
      // ๋น„์–ด์žˆ์„ ๊ฒฝ์šฐ ๋ชจ๋“  ์กฐ๊ฑด์— true
      if (idKeyword === '') return true
      if (targetId.includes(idKeyword)) return true
      return false
    }

    const matchDate = (targetDate: string) => {
      const { date: dateKeyword } = data
      // ๋น„์–ด์žˆ์„ ๊ฒฝ์šฐ ๋ชจ๋“  ์กฐ๊ฑด์— true
      if (dateKeyword.start === '' && dateKeyword.end === '') return true
      if (
        targetDate >= dayjs(dateKeyword.start).format('YYYY-MM-DD') &&
        targetDate <= dayjs(dateKeyword.end).format('YYYY-MM-DD')
      )
        return true
      return false
    }

    const matchMemberSeq = (targetSeq: number) => {
      const { userNumber: memberSeqKeyword } = data
      // ๋น„์–ด์žˆ์„ ๊ฒฝ์šฐ ๋ชจ๋“  ์กฐ๊ฑด์— true
      if (memberSeqKeyword === 0) return true
      if (memberSeqKeyword === targetSeq) return true
      return false
    }

    const userData = userLoginDataJSON.filter((user) => {
      return matchId(user.id) && matchMemberSeq(user.member_seq) && matchDate(user.create_date)
    })

    return userData
  }
profile
์ฝ”๋“œ๋กœ ์†Œํ†ตํ•˜๊ธฐ ์œ„ํ•ด ํž˜์“ฐ๋Š” ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž ์ž…๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€