mirror of
https://github.com/vercel/commerce.git
synced 2025-05-12 04:37:51 +00:00
36 lines
1020 B
TypeScript
36 lines
1020 B
TypeScript
'use client';
|
|
|
|
import { Order, WarrantyStatus } from 'lib/shopify/types';
|
|
import { isBeforeToday } from 'lib/utils';
|
|
import { useState } from 'react';
|
|
import ActivateWarrantyModal from './activate-warranty-modal';
|
|
import WarrantyActivatedBadge from './warranty-activated-badge';
|
|
import { Button } from 'components/ui';
|
|
|
|
type ActivateWarrantyModalProps = {
|
|
order: Order;
|
|
};
|
|
|
|
const ActivateWarranty = ({ order }: ActivateWarrantyModalProps) => {
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const isWarrantyActivated = order?.warrantyStatus?.value === WarrantyStatus.Activated;
|
|
const isPassDeadline = isBeforeToday(order?.warrantyActivationDeadline?.value);
|
|
|
|
if (isWarrantyActivated) {
|
|
return <WarrantyActivatedBadge />;
|
|
}
|
|
|
|
if (isPassDeadline) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<Button onClick={() => setIsOpen(true)}>Activate Warranty</Button>
|
|
<ActivateWarrantyModal isOpen={isOpen} onClose={() => setIsOpen(false)} order={order} />
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default ActivateWarranty;
|