All files / src/components/features/account/MyAccount AddressesTab.tsx

16.81% Statements 19/113
100% Branches 0/0
0% Functions 0/1
16.81% Lines 19/113

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 1141x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                                                                                                                                                                                              
"use client";
import React from "react";
import AddressCard, { EmptyAddressCard } from "./AddressCard";
import { Address } from "@/types/user";
import { Button } from "@/components/ui";
import { Icon } from "@/components/ui/icons";
 
const SHIPPING_ICON = "truck";
 
interface AddressesTabProps {
  shippingAddresses: Address[];
  billingAddresses: Address[];
  loading: boolean;
  onEditAddress: (address: Address) => void;
  onAddAddress: (type: "SHIPPING" | "BILLING") => void;
  onSetDefault: (addressId: number) => void;
  onDeleteAddress: (address: Address) => void;
}
 
export default function AddressesTab({
  shippingAddresses,
  billingAddresses,
  loading,
  onEditAddress,
  onAddAddress,
  onSetDefault,
  onDeleteAddress }: AddressesTabProps) {
  if (loading) {
    return (
      <div className="xl:max-w-[770px] w-full">
        <div className="animate-pulse space-y-6">
          <div className="h-8 bg-gray-200 dark:bg-gray-700 rounded w-1/4"></div>
          <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
            <div className="h-48 bg-gray-200 dark:bg-gray-700 rounded-xl"></div>
            <div className="h-48 bg-gray-200 dark:bg-gray-700 rounded-xl"></div>
          </div>
        </div>
      </div>
    );
  }

  return (
    <div className="xl:max-w-[770px] w-full space-y-8">
      {/* Shipping Addresses Section */}
      <div>
        <div className="flex items-center justify-between mb-4">
          <h3 className="font-medium text-xl text-dark dark:text-white flex items-center gap-2">
            <Icon name={SHIPPING_ICON} size={24} className="text-blue" />
            Shipping Addresses
          </h3>
          <Button
            variant="secondary"
            size="sm"
            onClick={() => onAddAddress("SHIPPING")}
          >
            <Icon name="plus" size={16} className="mr-1" />
            Add New
          </Button>
        </div>

        {shippingAddresses.length === 0 ? (
          <EmptyAddressCard type="SHIPPING" onAdd={() => onAddAddress("SHIPPING")} />
        ) : (
          <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
            {shippingAddresses.map((address) => (
              <AddressCard
                key={address.id}
                address={address}
                onEdit={() => onEditAddress(address)}
                onSetDefault={() => onSetDefault(address.id)}
                onDelete={() => onDeleteAddress(address)}
              />
            ))}
          </div>
        )}
      </div>

      {/* Billing Addresses Section */}
      <div>
        <div className="flex items-center justify-between mb-4">
          <h3 className="font-medium text-xl text-dark dark:text-white flex items-center gap-2">
            <Icon name="credit-card" size={24} className="text-green" />
            Billing Addresses
          </h3>
          <Button
            variant="secondary"
            size="sm"
            onClick={() => onAddAddress("BILLING")}
          >
            <Icon name="plus" size={16} className="mr-1" />
            Add New
          </Button>
        </div>

        {billingAddresses.length === 0 ? (
          <EmptyAddressCard type="BILLING" onAdd={() => onAddAddress("BILLING")} />
        ) : (
          <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
            {billingAddresses.map((address) => (
              <AddressCard
                key={address.id}
                address={address}
                onEdit={() => onEditAddress(address)}
                onSetDefault={() => onSetDefault(address.id)}
                onDelete={() => onDeleteAddress(address)}
              />
            ))}
          </div>
        )}
      </div>
    </div>
  );
}