All files / app/features/messages/requests HostRequestRespondButtons.tsx

0% Statements 0/19
0% Branches 0/15
0% Functions 0/3
0% Lines 0/19

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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108                                                                                                                                                                                                                       
import ConfirmationDialogWrapper from "components/ConfirmationDialogWrapper";
import { useTranslation } from "i18n";
import { GLOBAL, MESSAGES } from "i18n/namespaces";
import { HostRequestStatus } from "proto/conversations_pb";
import React from "react";
 
import FieldButton from "./FieldButton";
 
export default function HostRequestRespondButtons({
  isHost,
  status,
  isLoading,
  handleStatus,
}: {
  isHost: boolean;
  status: HostRequestStatus;
  isLoading: boolean;
  handleStatus: (status: HostRequestStatus) => () => void;
}) {
  const { t } = useTranslation([MESSAGES, GLOBAL]);
 
  const handleAccept = handleStatus(
    HostRequestStatus.HOST_REQUEST_STATUS_ACCEPTED
  );
  const handleReject = handleStatus(
    HostRequestStatus.HOST_REQUEST_STATUS_REJECTED
  );
  const handleCancel = handleStatus(
    HostRequestStatus.HOST_REQUEST_STATUS_CANCELLED
  );
  const handleConfirm = handleStatus(
    HostRequestStatus.HOST_REQUEST_STATUS_CONFIRMED
  );
 
  if (isHost) {
    const canAccept =
      status === HostRequestStatus.HOST_REQUEST_STATUS_PENDING ||
      status === HostRequestStatus.HOST_REQUEST_STATUS_REJECTED;
 
    const canReject =
      status === HostRequestStatus.HOST_REQUEST_STATUS_PENDING ||
      status === HostRequestStatus.HOST_REQUEST_STATUS_ACCEPTED ||
      status === HostRequestStatus.HOST_REQUEST_STATUS_CONFIRMED;
 
    return (
      <>
        {canAccept && (
          <FieldButton callback={handleAccept} isLoading={isLoading}>
            {t("global:accept")}
          </FieldButton>
        )}
        {canReject && (
          <ConfirmationDialogWrapper
            title={t("messages:close_request_dialog_title")}
            message={t("messages:close_request_dialog_host")}
            onConfirm={handleReject}
          >
            {(setIsOpen) => (
              <FieldButton
                isLoading={isLoading}
                callback={() => setIsOpen(true)}
              >
                {t("messages:close_request_button_text")}
              </FieldButton>
            )}
          </ConfirmationDialogWrapper>
        )}
      </>
    );
  } else {
    //user is the surfer
    const canConfirm =
      status === HostRequestStatus.HOST_REQUEST_STATUS_ACCEPTED;
 
    const canCancel =
      status === HostRequestStatus.HOST_REQUEST_STATUS_PENDING ||
      status === HostRequestStatus.HOST_REQUEST_STATUS_ACCEPTED ||
      status === HostRequestStatus.HOST_REQUEST_STATUS_REJECTED ||
      status === HostRequestStatus.HOST_REQUEST_STATUS_CONFIRMED;
 
    return (
      <>
        {canConfirm && (
          <FieldButton callback={handleConfirm} isLoading={isLoading}>
            {t("messages:confirm_request_button_text")}
          </FieldButton>
        )}
        {canCancel && (
          <ConfirmationDialogWrapper
            title={t("messages:close_request_dialog_title")}
            message={t("messages:close_request_dialog_surfer")}
            onConfirm={handleCancel}
          >
            {(setIsOpen) => (
              <FieldButton
                isLoading={isLoading}
                callback={() => setIsOpen(true)}
              >
                {t("global:cancel")}
              </FieldButton>
            )}
          </ConfirmationDialogWrapper>
        )}
      </>
    );
  }
}