All files / src/components/pages/group/group-buttons index.tsx

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

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                                                                                       
'use client';

import { FinishedButton } from '@/components/pages/group/group-buttons/finished-button';
import { JoiningButton } from '@/components/pages/group/group-buttons/joining-button';
import { MembersButton } from '@/components/pages/group/group-buttons/members-button';
import { PendingButton } from '@/components/pages/group/group-buttons/pending-button';
import { GetGroupDetailsResponse } from '@/types/service/group';

interface Props {
  statuses: Pick<GetGroupDetailsResponse, 'status' | 'myMembership' | 'joinPolicy'>;
  chatRoomId: GetGroupDetailsResponse['chatRoomId'];
}

export const GroupButtons = ({
  statuses: { status, myMembership, joinPolicy },
  chatRoomId,
}: Props) => {
  const isMember = myMembership?.status === 'ATTEND' && status !== 'FINISHED';

  const isPending = myMembership?.status === 'PENDING' && status !== 'FINISHED';

  const isFinished = status === 'FINISHED';

  const canJoin = !isMember && !isPending && !isFinished;

  return (
    <div className='sticky bottom-[56px] border-t-1 border-gray-200 bg-white px-4 py-3'>
      {canJoin && (
        <JoiningButton
          conditions={{ isGroupFull: status === 'FULL', isFreeGroup: joinPolicy === 'FREE' }}
        />
      )}
      {isPending && <PendingButton />}
      {isMember && (
        <MembersButton
          chatRoomId={chatRoomId}
          conditions={{ isHost: myMembership.role === 'HOST' }}
        />
      )}
      {isFinished && <FinishedButton />}
    </div>
  );
};