All files / libs/payout-definition/plans/views/hub/rule-designer/src/lib/summary PlanHubRuleDesignerSummary.tsx

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

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                                                                                                                                                   
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { memo } from 'react';
import { FormattedMessage } from 'react-intl';

import { Badge, Group, Skeleton, Typography } from '@allshares/studio-design-system';
import { isRulePayout } from '@amalia/payout-definition/plans/types';

import { RuleDesignerComputeResult } from '../compute/result/RuleDesignerComputeResult';
import { useDesignerLibrary } from '../hooks/use-designer-library';
import { usePlanHubRuleDesignerContext } from '../PlanHubRuleDesigner.context';
import { type PlanHubRuleDesignerStepTabs } from '../tabs/plan-hub-rule-designer-step-tabs.types';

const StyledContainer = styled(Group)`
  height: 80px;
  padding-left: 32px;
  padding-right: 24px;
  border-bottom: 1px solid ${({ theme }) => theme.ds.colors.gray[100]};
  width: 100%;
  flex-shrink: 0;

  [data-color-scheme='dark'] & {
    border-color: ${({ theme }) => theme.ds.colors.dark[600]};
  }
`;

const RULE_NAME_PLACEHOLDER = 'Rule name';

export interface PlanHubRuleDesignerSummaryProps {
  readonly selectedRuleDesignerTab: PlanHubRuleDesignerStepTabs;
}

export const PlanHubRuleDesignerSummary = memo(function PlanHubRuleDesignerSummary({
  selectedRuleDesignerTab,
}: PlanHubRuleDesignerSummaryProps) {
  const { accessors } = useDesignerLibrary();
  const { ruleId } = usePlanHubRuleDesignerContext();

  const ruleDefinition = accessors.getRuleById(ruleId);
  const ruleName = ruleDefinition?.name;

  return (
    <StyledContainer
      align="center"
      gap={16}
      justify="space-between"
    >
      <Skeleton visible={!ruleName}>
        <Typography variant="heading4Medium">{ruleName ?? RULE_NAME_PLACEHOLDER}</Typography>
      </Skeleton>
      {!isRulePayout(ruleDefinition) && (
        <div
          css={css`
            flex: 1;
          `}
        >
          <Badge
            size="small"
            variant="grey"
          >
            <FormattedMessage defaultMessage="Non-payout" />
          </Badge>
        </div>
      )}
      {!!ruleDefinition && (
        <RuleDesignerComputeResult
          highlightPayout={selectedRuleDesignerTab === '3-configure-payment'}
          ruleDefinition={ruleDefinition}
        />
      )}
    </StyledContainer>
  );
});