All files / src/features/setting/components billing-section.tsx

100% Statements 3/3
100% Branches 8/8
100% Functions 1/1
100% Lines 3/3

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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180                          1x                       32x   32x                                                                                                                                                                                                                                                                                                                
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from '@/components/collapse';
import { Button } from '@/components/button';
import { Input } from '@/components/input';
import { FormMessage } from '@/components/form-message';
import { Heading } from '@/components/heading';
import { Text } from '@/components/text';
import { useBillingSettings } from '../hooks/use-billing-settings';
import { BILLING_SECTION } from '@/constants/setting';
 
export const BillingSection = () => {
  const {
    control,
    error,
    success,
    showForm,
    isSubmitting,
    handleSubmit,
    handleEditCard,
    handleCancel,
    dismissError,
    dismissSuccess,
  } = useBillingSettings();
 
  return (
    <Collapsible className="border-b border-gray-200">
      <CollapsibleTrigger className="w-full text-left border-0 p-6">
        <Heading as="h3" size="h5">
          {BILLING_SECTION.TITLE}
        </Heading>
      </CollapsibleTrigger>
      <CollapsibleContent className="border-0 p-0">
        <div className="w-[297px] py-6 mx-auto">
          {/* Error Message */}
          {error && (
            <FormMessage
              type="error"
              message={error}
              onDismiss={dismissError}
            />
          )}
 
          {/* Success Message */}
          {success && (
            <FormMessage
              type="success"
              message={success}
              onDismiss={dismissSuccess}
            />
          )}
 
          {!showForm ? (
            <>
              <Text
                size="xs"
                className="mb-4 text-center text-default leading-relaxed"
              >
                {BILLING_SECTION.INFO_TEXT}
              </Text>
              <div
                className="h-[187px] rounded-lg p-4 text-white mb-6 bg-cover bg-center bg-no-repeat"
                style={{
                  backgroundImage: `linear-gradient(135deg, #667eea 0%, #764ba2 100%)`,
                }}
              >
                <div className="h-full flex flex-col justify-between">
                  <div>
                    <Text size="xs" className="opacity-80">
                      {BILLING_SECTION.CARD_DISPLAY.BANK_ACCOUNT_LABEL}
                    </Text>
                    <Text size="lg" weight="semibold">
                      {BILLING_SECTION.CARD_DISPLAY.BANK_ACCOUNT_VALUE}
                    </Text>
                  </div>
                  <div className="flex justify-between items-end">
                    <div>
                      <Text size="xs" className="opacity-80">
                        {BILLING_SECTION.CARD_DISPLAY.EXPIRY_DATE_LABEL}
                      </Text>
                      <Text size="sm">
                        {BILLING_SECTION.CARD_DISPLAY.EXPIRY_DATE_VALUE}
                      </Text>
                    </div>
                    <div className="text-right">
                      <Text size="xs" className="opacity-80">
                        {BILLING_SECTION.CARD_DISPLAY.CVV_LABEL}
                      </Text>
                      <Text size="sm">
                        {BILLING_SECTION.CARD_DISPLAY.CVV_VALUE}
                      </Text>
                    </div>
                  </div>
                </div>
              </div>
              <div className="flex justify-center">
                <Button
                  onClick={handleEditCard}
                  className="bg-gradient-vertical hover:opacity-90 text-white px-6 py-2"
                >
                  {BILLING_SECTION.BUTTONS.EDIT.TEXT}
                </Button>
              </div>
            </>
          ) : (
            <form onSubmit={handleSubmit} className="flex flex-col gap-4">
              <Input
                name={'holderName' as any}
                control={control as any}
                id="holderName"
                label={BILLING_SECTION.FIELDS.HOLDER_NAME.LABEL}
                placeholder={BILLING_SECTION.FIELDS.HOLDER_NAME.PLACEHOLDER}
                className="h-[50px]"
                disabled={isSubmitting}
              />
 
              <Input
                name={'cardNumber' as any}
                control={control as any}
                id="cardNumber"
                label={BILLING_SECTION.FIELDS.CARD_NUMBER.LABEL}
                placeholder={BILLING_SECTION.FIELDS.CARD_NUMBER.PLACEHOLDER}
                maxLength={BILLING_SECTION.FIELDS.CARD_NUMBER.MAX_LENGTH}
                className="h-[50px]"
                disabled={isSubmitting}
              />
 
              <div className="flex gap-4">
                <Input
                  name={'expiryDate' as any}
                  control={control as any}
                  id="expiryDate"
                  label={BILLING_SECTION.FIELDS.EXPIRY_DATE.LABEL}
                  placeholder={BILLING_SECTION.FIELDS.EXPIRY_DATE.PLACEHOLDER}
                  maxLength={BILLING_SECTION.FIELDS.EXPIRY_DATE.MAX_LENGTH}
                  className="h-[50px]"
                  disabled={isSubmitting}
                />
 
                <Input
                  name={'cvv' as any}
                  control={control as any}
                  id="cvv"
                  label={BILLING_SECTION.FIELDS.CVV.LABEL}
                  placeholder={BILLING_SECTION.FIELDS.CVV.PLACEHOLDER}
                  maxLength={BILLING_SECTION.FIELDS.CVV.MAX_LENGTH}
                  className="h-[50px]"
                  disabled={isSubmitting}
                />
              </div>
 
              <div className="flex justify-center gap-4 mt-4">
                <Button
                  type="button"
                  onClick={handleCancel}
                  className="bg-gray-200 hover:bg-gray-300 text-gray-700 px-6 py-2"
                  disabled={isSubmitting}
                >
                  {BILLING_SECTION.BUTTONS.CANCEL.TEXT}
                </Button>
                <Button
                  type="submit"
                  className="bg-gradient-vertical hover:opacity-90 text-white px-6 py-2"
                  disabled={isSubmitting}
                >
                  {isSubmitting
                    ? BILLING_SECTION.BUTTONS.SAVE.LOADING_TEXT
                    : BILLING_SECTION.BUTTONS.SAVE.TEXT}
                </Button>
              </div>
            </form>
          )}
        </div>
      </CollapsibleContent>
    </Collapsible>
  );
};