All files / src/components/pages/group/group-descriptions/description-sections/description-progress index.tsx

0% Statements 0/44
0% Branches 0/1
0% Functions 0/1
0% Lines 0/44

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45                                                                                         
import { useEffect, useState } from 'react';

import { formatTimeAgo } from '@/lib/formatDateTime';
import { GetGroupDetailsResponse } from '@/types/service/group';

interface Props {
  progress: {
    maxParticipants: GetGroupDetailsResponse['maxParticipants'];
    participantCount: GetGroupDetailsResponse['participantCount'];
  };
  createdAt: GetGroupDetailsResponse['createdAt'];
}

export const DescriptionProgress = ({
  progress: { maxParticipants, participantCount },
  createdAt,
}: Props) => {
  const [timeAgo, setTimeAgo] = useState<string | null>(null);
  const progressRate = Math.ceil((participantCount / maxParticipants) * 100);

  useEffect(() => {
    setTimeAgo(formatTimeAgo(createdAt));
  }, [createdAt]);

  return (
    <div className='mt-6 select-none'>
      <div className='space-y-1 rounded-2xl border border-gray-300 bg-gray-50 px-4 py-[14px]'>
        <div className='flex-between'>
          <p className='text-text-xs-medium text-gray-700'>참여 인원</p>
          <span className='text-mint-600 text-text-xs-semibold'>
            {participantCount}/{maxParticipants}
          </span>
        </div>
        <div className='h-2 w-full overflow-hidden rounded-full bg-gray-300'>
          <span className='bg-mint-500 block h-2' style={{ width: `${progressRate}%` }} />
        </div>
      </div>

      <div className='mt-4'>
        <p className='text-text-xs-medium h-4.5 text-right text-gray-500'>{timeAgo}</p>
      </div>
    </div>
  );
};