Cart fixes (backend), adjusted header, added footer, mobile formatting updates
This commit is contained in:
7
.claude/settings.local.json
Normal file
7
.claude/settings.local.json
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"allow": [
|
||||||
|
"Bash(grep -E \"\\\\.\\(tsx?|jsx?\\)$\")"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,4 +91,13 @@ public class CartController {
|
|||||||
|
|
||||||
return ResponseEntity.noContent().build();
|
return ResponseEntity.noContent().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/checkout/cancel")
|
||||||
|
@PreAuthorize("isAuthenticated()")
|
||||||
|
public ResponseEntity<Void> cancelCheckout(@RequestParam Long storeId) {
|
||||||
|
Long userId = AuthenticationHelper.getAuthenticatedUserId();
|
||||||
|
cartService.cancelCheckout(userId, storeId);
|
||||||
|
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class CartResponse {
|
|||||||
private String couponCode;
|
private String couponCode;
|
||||||
private Boolean pointsApplied;
|
private Boolean pointsApplied;
|
||||||
private Integer availableLoyaltyPoints;
|
private Integer availableLoyaltyPoints;
|
||||||
|
private Boolean checkoutPending;
|
||||||
|
|
||||||
public CartResponse() {
|
public CartResponse() {
|
||||||
}
|
}
|
||||||
@@ -53,4 +54,7 @@ public class CartResponse {
|
|||||||
public Integer getAvailableLoyaltyPoints() { return availableLoyaltyPoints; }
|
public Integer getAvailableLoyaltyPoints() { return availableLoyaltyPoints; }
|
||||||
public void setAvailableLoyaltyPoints(Integer availableLoyaltyPoints) { this.availableLoyaltyPoints = availableLoyaltyPoints; }
|
public void setAvailableLoyaltyPoints(Integer availableLoyaltyPoints) { this.availableLoyaltyPoints = availableLoyaltyPoints; }
|
||||||
|
|
||||||
|
public Boolean getCheckoutPending() { return checkoutPending; }
|
||||||
|
public void setCheckoutPending(Boolean checkoutPending) { this.checkoutPending = checkoutPending; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -482,15 +482,21 @@ public class CartService {
|
|||||||
List<CartItemResponse> itemResponses = cartItemRepository
|
List<CartItemResponse> itemResponses = cartItemRepository
|
||||||
.findByCartCartId(cart.getCartId())
|
.findByCartCartId(cart.getCartId())
|
||||||
.stream()
|
.stream()
|
||||||
.map(item -> new CartItemResponse(
|
.map(item -> {
|
||||||
item.getCartItemId(),
|
String rawImageUrl = item.getProduct().getImageUrl();
|
||||||
item.getProduct().getProdId(),
|
String imageUrl = (rawImageUrl != null && !rawImageUrl.isBlank())
|
||||||
item.getProduct().getProdName(),
|
? "/api/v1/products/" + item.getProduct().getProdId() + "/image"
|
||||||
item.getProduct().getImageUrl(),
|
: null;
|
||||||
item.getUnitPrice(),
|
return new CartItemResponse(
|
||||||
item.getQuantity(),
|
item.getCartItemId(),
|
||||||
item.getUnitPrice().multiply(BigDecimal.valueOf(item.getQuantity()))
|
item.getProduct().getProdId(),
|
||||||
))
|
item.getProduct().getProdName(),
|
||||||
|
imageUrl,
|
||||||
|
item.getUnitPrice(),
|
||||||
|
item.getQuantity(),
|
||||||
|
item.getUnitPrice().multiply(BigDecimal.valueOf(item.getQuantity()))
|
||||||
|
);
|
||||||
|
})
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
CartResponse response = new CartResponse();
|
CartResponse response = new CartResponse();
|
||||||
@@ -505,7 +511,23 @@ public class CartService {
|
|||||||
response.setCouponCode(cart.getCoupon() != null ? cart.getCoupon().getCouponCode() : null);
|
response.setCouponCode(cart.getCoupon() != null ? cart.getCoupon().getCouponCode() : null);
|
||||||
response.setPointsApplied(cart.getPointsApplied());
|
response.setPointsApplied(cart.getPointsApplied());
|
||||||
response.setAvailableLoyaltyPoints(cart.getUser() != null ? cart.getUser().getLoyaltyPoints() : null);
|
response.setAvailableLoyaltyPoints(cart.getUser() != null ? cart.getUser().getLoyaltyPoints() : null);
|
||||||
|
response.setCheckoutPending(cart.getCheckoutPending());
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void cancelCheckout(Long userId, Long storeId) {
|
||||||
|
cartRepository.findActiveCartByUserAndStore(userId, storeId, "ACTIVE")
|
||||||
|
.ifPresent(cart -> {
|
||||||
|
if (!Boolean.TRUE.equals(cart.getCheckoutPending())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cart.setCheckoutPending(false);
|
||||||
|
cart.setCheckoutAmount(null);
|
||||||
|
cart.setCheckoutStartedAt(null);
|
||||||
|
cart.setCheckoutPaymentIntentId(null);
|
||||||
|
cartRepository.save(cart);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ export default function AdoptPage() {
|
|||||||
const [pets, setPets] = useState([]);
|
const [pets, setPets] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
const [health, setHealth] = useState(null);
|
|
||||||
|
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [query, setQuery] = useState("");
|
const [query, setQuery] = useState("");
|
||||||
@@ -26,16 +25,9 @@ export default function AdoptPage() {
|
|||||||
// Species options come from a dedicated fetch (only store-filtered, no species filter)
|
// Species options come from a dedicated fetch (only store-filtered, no species filter)
|
||||||
const [speciesOptions, setSpeciesOptions] = useState([]);
|
const [speciesOptions, setSpeciesOptions] = useState([]);
|
||||||
|
|
||||||
// ---------- health check ----------
|
|
||||||
useEffect(() => {
|
|
||||||
fetch(`${API_BASE}/api/v1/health`)
|
|
||||||
.then((res) => (res.ok ? setHealth("online") : setHealth("error")))
|
|
||||||
.catch(() => setHealth("offline"));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSelectedSpecies("");
|
setSelectedSpecies("");
|
||||||
const params = new URLSearchParams({ status: "Available", page: "0", size: String(PAGE_SIZE) });
|
const params = new URLSearchParams({ page: "0", size: String(PAGE_SIZE) });
|
||||||
if (selectedStoreId) params.set("storeId", String(selectedStoreId));
|
if (selectedStoreId) params.set("storeId", String(selectedStoreId));
|
||||||
|
|
||||||
fetch(`${API_BASE}/api/v1/pets?${params}`)
|
fetch(`${API_BASE}/api/v1/pets?${params}`)
|
||||||
@@ -62,7 +54,6 @@ export default function AdoptPage() {
|
|||||||
page: String(page),
|
page: String(page),
|
||||||
size: String(PAGE_SIZE),
|
size: String(PAGE_SIZE),
|
||||||
sort: "id,asc",
|
sort: "id,asc",
|
||||||
status: "Available",
|
|
||||||
});
|
});
|
||||||
if (query) params.set("q", query);
|
if (query) params.set("q", query);
|
||||||
if (selectedSpecies) params.set("species", selectedSpecies);
|
if (selectedSpecies) params.set("species", selectedSpecies);
|
||||||
@@ -161,15 +152,6 @@ export default function AdoptPage() {
|
|||||||
Clear Filters
|
Clear Filters
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<span
|
|
||||||
className={`backend-status backend-status--${health ?? "checking"}`}
|
|
||||||
title={
|
|
||||||
health === "online" ? "Backend online" :
|
|
||||||
health === "offline" ? "Backend offline" :
|
|
||||||
health === "error" ? "Backend error" : "Checking…"
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
@@ -180,13 +162,7 @@ export default function AdoptPage() {
|
|||||||
<div className="adopt-error-box">
|
<div className="adopt-error-box">
|
||||||
<p className="adopt-error-title">Failed to load pets</p>
|
<p className="adopt-error-title">Failed to load pets</p>
|
||||||
<code className="adopt-error-detail">{error}</code>
|
<code className="adopt-error-detail">{error}</code>
|
||||||
<p className="adopt-error-hint">
|
<p className="adopt-error-hint">Make sure the backend is running and try again.</p>
|
||||||
{health === "offline"
|
|
||||||
? "The Spring Boot backend is not reachable. Make sure it is running in IntelliJ on port 8080."
|
|
||||||
: health === "error"
|
|
||||||
? "The backend responded with an error. Check the IntelliJ Run console for stack traces."
|
|
||||||
: "The backend is reachable but the /pets endpoint failed. Check the IntelliJ Run console."}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ export default function CartPage() {
|
|||||||
clearCart,
|
clearCart,
|
||||||
applyCoupon,
|
applyCoupon,
|
||||||
checkout,
|
checkout,
|
||||||
|
cancelCheckout,
|
||||||
} = useCart();
|
} = useCart();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
@@ -114,6 +115,14 @@ export default function CartPage() {
|
|||||||
}
|
}
|
||||||
}, [cart]);
|
}, [cart]);
|
||||||
|
|
||||||
|
// If the cart arrives already locked (e.g. user closed the page mid-checkout)
|
||||||
|
// and there is no active Stripe session, release the lock automatically.
|
||||||
|
useEffect(() => {
|
||||||
|
if (cart?.checkoutPending && !clientSecret) {
|
||||||
|
cancelCheckout().catch(() => {});
|
||||||
|
}
|
||||||
|
}, [cart?.checkoutPending, clientSecret, cancelCheckout]);
|
||||||
|
|
||||||
async function handleQuantityChange(cartItemId, newQty) {
|
async function handleQuantityChange(cartItemId, newQty) {
|
||||||
if (newQty < 1) {
|
if (newQty < 1) {
|
||||||
return;
|
return;
|
||||||
@@ -351,7 +360,10 @@ export default function CartPage() {
|
|||||||
setClientSecret(null);
|
setClientSecret(null);
|
||||||
setConfirmed(true);
|
setConfirmed(true);
|
||||||
}}
|
}}
|
||||||
onCancel={() => setClientSecret(null)}
|
onCancel={async () => {
|
||||||
|
await cancelCheckout().catch(() => {});
|
||||||
|
setClientSecret(null);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</Elements>
|
</Elements>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -30,13 +30,14 @@ body {
|
|||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: orange;
|
background: #e68672;
|
||||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
padding: 0.5rem 2rem;
|
padding: 0.5rem 2rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 70px;
|
flex-wrap: wrap;
|
||||||
|
min-height: 70px;
|
||||||
border-radius: 0px 0px 10px 10px;
|
border-radius: 0px 0px 10px 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,12 +63,15 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 2rem;
|
gap: 2rem;
|
||||||
margin-left: 2rem;
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Indivdual Link Styles */
|
/* Indivdual Link Styles */
|
||||||
.nav-link {
|
.nav-link {
|
||||||
color: rgb(255, 255, 255);
|
color: #2f2f2f;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
padding: 0.5rem 1rem;
|
padding: 0.5rem 1rem;
|
||||||
@@ -365,7 +369,7 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
height: 160px;
|
aspect-ratio: 1 / 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pet-card-emoji {
|
.pet-card-emoji {
|
||||||
@@ -380,31 +384,34 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.pet-card-body {
|
.pet-card-body {
|
||||||
padding: 1rem 1.25rem 1.25rem;
|
padding: 0.6rem 0.75rem 0.75rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 0.3rem;
|
gap: 0.2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pet-card-name {
|
.pet-card-name {
|
||||||
font-size: 1.2rem;
|
font-size: 0.95rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: #222;
|
color: #222;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pet-card-species {
|
.pet-card-species {
|
||||||
font-size: 0.95rem;
|
font-size: 0.8rem;
|
||||||
color: #666;
|
color: #666;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pet-card-status {
|
.pet-card-status {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-top: 0.4rem;
|
margin-top: 0.2rem;
|
||||||
padding: 0.2rem 0.75rem;
|
padding: 0.15rem 0.5rem;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
font-size: 0.8rem;
|
font-size: 0.7rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
@@ -595,6 +602,71 @@ body {
|
|||||||
margin: 0 0 1rem;
|
margin: 0 0 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.product-qty-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-qty-label {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-qty-controls {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-add-to-cart-btn {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.85rem;
|
||||||
|
background: #e68672;
|
||||||
|
color: #2f2f2f;
|
||||||
|
border: none;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.2s ease, transform 0.1s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-add-to-cart-btn:hover:not(:disabled) {
|
||||||
|
background: #d4705e;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-add-to-cart-btn:active:not(:disabled) {
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-add-to-cart-btn:disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-cart-feedback {
|
||||||
|
margin: 0.75rem 0 0;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 0.6rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-cart-feedback--success {
|
||||||
|
background: #f0fff4;
|
||||||
|
border: 1px solid #b2dfdb;
|
||||||
|
color: #1a7a3c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.product-cart-feedback--error {
|
||||||
|
background: #fff0f0;
|
||||||
|
border: 1px solid #f5c6c6;
|
||||||
|
color: #c0392b;
|
||||||
|
}
|
||||||
|
|
||||||
.pet-detail-cta-btn {
|
.pet-detail-cta-btn {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0.65rem 1.5rem;
|
padding: 0.65rem 1.5rem;
|
||||||
@@ -733,8 +805,8 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.adopt-grid {
|
.adopt-grid {
|
||||||
grid-template-columns: repeat(2, 1fr);
|
grid-template-columns: repeat(3, 1fr);
|
||||||
gap: 1.25rem;
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pet-detail-card {
|
.pet-detail-card {
|
||||||
@@ -754,7 +826,8 @@ body {
|
|||||||
|
|
||||||
@media (max-width: 480px) {
|
@media (max-width: 480px) {
|
||||||
.adopt-grid {
|
.adopt-grid {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
gap: 0.6rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.adopt-hero-title,
|
.adopt-hero-title,
|
||||||
@@ -884,29 +957,6 @@ body {
|
|||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.backend-status {
|
|
||||||
display: inline-block;
|
|
||||||
width: 12px;
|
|
||||||
height: 12px;
|
|
||||||
border-radius: 50%;
|
|
||||||
flex-shrink: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.backend-status--online {
|
|
||||||
background: #1a7a3c;
|
|
||||||
}
|
|
||||||
|
|
||||||
.backend-status--offline {
|
|
||||||
background: #c0392b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.backend-status--error {
|
|
||||||
background: #e67e00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.backend-status--checking {
|
|
||||||
background: #bbb;
|
|
||||||
}
|
|
||||||
|
|
||||||
.adopt-error-box {
|
.adopt-error-box {
|
||||||
max-width: 640px;
|
max-width: 640px;
|
||||||
@@ -964,21 +1014,21 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.nav-register-btn {
|
.nav-register-btn {
|
||||||
background: white;
|
background: #2f2f2f;
|
||||||
color: orange !important;
|
color: #e68672 !important;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
padding: 0.4rem 1rem !important;
|
padding: 0.4rem 1rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-register-btn:hover {
|
.nav-register-btn:hover {
|
||||||
background: #fff3e0 !important;
|
background: #444 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-logout-btn {
|
.nav-logout-btn {
|
||||||
background: rgba(255, 255, 255, 0.2);
|
background: rgba(47, 47, 47, 0.15);
|
||||||
color: white;
|
color: #2f2f2f;
|
||||||
border: 1px solid rgba(255, 255, 255, 0.6);
|
border: 1px solid rgba(47, 47, 47, 0.4);
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
padding: 0.35rem 1rem;
|
padding: 0.35rem 1rem;
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
@@ -988,7 +1038,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.nav-logout-btn:hover {
|
.nav-logout-btn:hover {
|
||||||
background: rgba(255, 255, 255, 0.35);
|
background: rgba(47, 47, 47, 0.25);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Login/Register */
|
/* Login/Register */
|
||||||
@@ -1896,12 +1946,12 @@ body {
|
|||||||
color: #333;
|
color: #333;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Store Selector ──────────────────────────────────────── */
|
/* Store Selector */
|
||||||
|
|
||||||
.nav-store-select {
|
.nav-store-select {
|
||||||
background: rgba(255, 255, 255, 0.15);
|
background: rgba(47, 47, 47, 0.1);
|
||||||
color: white;
|
color: #2f2f2f;
|
||||||
border: 1px solid rgba(255, 255, 255, 0.4);
|
border: 1px solid rgba(47, 47, 47, 0.35);
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
padding: 0.3rem 0.6rem;
|
padding: 0.3rem 0.6rem;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
@@ -1912,15 +1962,15 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.nav-store-select option {
|
.nav-store-select option {
|
||||||
background: #333;
|
background: #fff;
|
||||||
color: white;
|
color: #2f2f2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-store-select:hover {
|
.nav-store-select:hover {
|
||||||
background: rgba(255, 255, 255, 0.25);
|
background: rgba(47, 47, 47, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Cart Badge ──────────────────────────────────────────── */
|
/* Cart Badge */
|
||||||
|
|
||||||
.nav-cart-btn {
|
.nav-cart-btn {
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -2422,3 +2472,355 @@ body {
|
|||||||
|
|
||||||
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }
|
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }
|
||||||
@keyframes spin { to { transform: rotate(360deg); } }
|
@keyframes spin { to { transform: rotate(360deg); } }
|
||||||
|
|
||||||
|
/* Footer */
|
||||||
|
.site-footer {
|
||||||
|
background: #e68672;
|
||||||
|
color: #2f2f2f;
|
||||||
|
margin-top: 4rem;
|
||||||
|
border-radius: 10px 10px 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-container {
|
||||||
|
max-width: 1200px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 3rem 2rem 2rem;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 2fr 1fr 1fr 1fr;
|
||||||
|
gap: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-logo {
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-tagline {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
opacity: 0.9;
|
||||||
|
max-width: 260px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-heading {
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-links {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-links a {
|
||||||
|
color: #2f2f2f;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
opacity: 0.85;
|
||||||
|
transition: opacity 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-links a:hover {
|
||||||
|
opacity: 1;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-contact li {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
opacity: 0.85;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-bottom {
|
||||||
|
border-top: 1px solid rgba(47, 47, 47, 0.2);
|
||||||
|
text-align: center;
|
||||||
|
padding: 1rem 2rem;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.footer-container {
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
.footer-brand {
|
||||||
|
grid-column: 1 / -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 550px) {
|
||||||
|
.footer-container {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mobile / Responsive */
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.navbar {
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hamburger button – hidden on desktop */
|
||||||
|
.nav-mobile-bar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-hamburger {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 5px;
|
||||||
|
width: 36px;
|
||||||
|
height: 36px;
|
||||||
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
padding: 4px;
|
||||||
|
border-radius: 6px;
|
||||||
|
transition: background 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-hamburger:hover {
|
||||||
|
background: rgba(47, 47, 47, 0.12);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-hamburger span {
|
||||||
|
display: block;
|
||||||
|
height: 2px;
|
||||||
|
width: 100%;
|
||||||
|
background: #2f2f2f;
|
||||||
|
border-radius: 2px;
|
||||||
|
transition: transform 0.25s ease, opacity 0.25s ease;
|
||||||
|
transform-origin: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Animate bars to X when open */
|
||||||
|
.nav-hamburger--open span:nth-child(1) {
|
||||||
|
transform: translateY(7px) rotate(45deg);
|
||||||
|
}
|
||||||
|
.nav-hamburger--open span:nth-child(2) {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
.nav-hamburger--open span:nth-child(3) {
|
||||||
|
transform: translateY(-7px) rotate(-45deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mobile slide-down drawer */
|
||||||
|
.nav-drawer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
/* Show hamburger bar, hide desktop nav */
|
||||||
|
.nav-mobile-bar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-links,
|
||||||
|
.nav-auth {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Drawer panel */
|
||||||
|
.nav-drawer {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
position: absolute;
|
||||||
|
top: 70px;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
background: #e68672;
|
||||||
|
padding: 1rem 1.5rem 1.5rem;
|
||||||
|
z-index: 999;
|
||||||
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
|
||||||
|
border-radius: 0 0 10px 10px;
|
||||||
|
gap: 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-drawer-link {
|
||||||
|
display: block;
|
||||||
|
color: #2f2f2f;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
font-weight: 500;
|
||||||
|
padding: 0.65rem 0.5rem;
|
||||||
|
border-radius: 6px;
|
||||||
|
transition: background 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-drawer-link:hover {
|
||||||
|
background: rgba(47, 47, 47, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-drawer-link--register {
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
background: #2f2f2f;
|
||||||
|
color: #e68672 !important;
|
||||||
|
font-weight: 700;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 0.6rem 1rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-drawer-link--register:hover {
|
||||||
|
background: #444 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-drawer-divider {
|
||||||
|
height: 1px;
|
||||||
|
background: rgba(47, 47, 47, 0.2);
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-store-select--drawer {
|
||||||
|
width: 100%;
|
||||||
|
margin: 0 0 0.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-logout-btn--drawer {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 0.25rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 0.65rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cart item row – stack on small screens */
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.cart-item-row {
|
||||||
|
grid-template-columns: 56px 1fr;
|
||||||
|
grid-template-rows: auto auto;
|
||||||
|
gap: 0.5rem 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cart-item-img {
|
||||||
|
width: 56px;
|
||||||
|
height: 56px;
|
||||||
|
grid-row: 1 / 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cart-item-details {
|
||||||
|
grid-column: 2;
|
||||||
|
grid-row: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cart-item-qty-controls {
|
||||||
|
grid-column: 2;
|
||||||
|
grid-row: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cart-item-line-total {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cart-item-remove {
|
||||||
|
position: absolute;
|
||||||
|
top: 0.75rem;
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cart-item-row {
|
||||||
|
position: relative;
|
||||||
|
padding-right: 2rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adopt filters - stack vertically on mobile */
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.adopt-filters-row {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.adopt-filter-group {
|
||||||
|
min-width: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.adopt-filter-select {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.adopt-search-form {
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.adopt-search-input {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.adopt-search-btn,
|
||||||
|
.adopt-clear-btn {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Appointments - fix adopt grid on narrow screens */
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.appt-adopt-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.appt-modal {
|
||||||
|
margin: 1rem;
|
||||||
|
padding: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.appt-slots-grid {
|
||||||
|
gap: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.appt-slot-btn {
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Auth pages - reduce padding on very small screens */
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.auth-card {
|
||||||
|
padding: 1.5rem 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-title {
|
||||||
|
font-size: 1.4rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Profile - tighten padding on mobile */
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.profile-card {
|
||||||
|
padding: 1.5rem 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-pets-section {
|
||||||
|
padding: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile-pets-header {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* General – prevent horizontal overflow on all pages */
|
||||||
|
html, body {
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
img, video, iframe {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Geist, Geist_Mono } from "next/font/google";
|
import { Geist, Geist_Mono } from "next/font/google";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
import DisplayNav from "@/components/Navigation";
|
import DisplayNav from "@/components/Navigation";
|
||||||
|
import Footer from "@/components/Footer";
|
||||||
import ClientProviders from "@/components/ClientProviders";
|
import ClientProviders from "@/components/ClientProviders";
|
||||||
|
|
||||||
export const metadata = {
|
export const metadata = {
|
||||||
@@ -15,6 +16,7 @@ export default function RootLayout({children}) {
|
|||||||
<ClientProviders>
|
<ClientProviders>
|
||||||
<DisplayNav />
|
<DisplayNav />
|
||||||
{children}
|
{children}
|
||||||
|
<Footer />
|
||||||
</ClientProviders>
|
</ClientProviders>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ export default function ProductDetailPage() {
|
|||||||
|
|
||||||
{!loading && !error && product && (
|
{!loading && !error && product && (
|
||||||
<ProductProfile
|
<ProductProfile
|
||||||
|
prodId={product.prodId}
|
||||||
prodName={product.prodName}
|
prodName={product.prodName}
|
||||||
categoryName={product.categoryName}
|
categoryName={product.categoryName}
|
||||||
prodDesc={product.prodDesc}
|
prodDesc={product.prodDesc}
|
||||||
|
|||||||
57
web/components/Footer.js
Normal file
57
web/components/Footer.js
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import Image from "next/image";
|
||||||
|
|
||||||
|
export default function Footer() {
|
||||||
|
return (
|
||||||
|
<footer className="site-footer">
|
||||||
|
<div className="footer-container">
|
||||||
|
|
||||||
|
<div className="footer-brand">
|
||||||
|
<Image
|
||||||
|
src="/logo_simple.png"
|
||||||
|
alt="Leon's Pet Store logo"
|
||||||
|
width={50}
|
||||||
|
height={50}
|
||||||
|
className="footer-logo"
|
||||||
|
/>
|
||||||
|
<p className="footer-tagline">
|
||||||
|
Your neighbourhood pet store!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="footer-section">
|
||||||
|
<h3 className="footer-heading">Quick Links</h3>
|
||||||
|
<ul className="footer-links">
|
||||||
|
<li><Link href="/">Home</Link></li>
|
||||||
|
<li><Link href="/adopt">Adopt a Pet</Link></li>
|
||||||
|
<li><Link href="/products">Online Store</Link></li>
|
||||||
|
<li><Link href="/appointments">Schedule an Appointment</Link></li>
|
||||||
|
<li><Link href="/ai-chat">AI Assistant</Link></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="footer-section">
|
||||||
|
<h3 className="footer-heading">Company</h3>
|
||||||
|
<ul className="footer-links">
|
||||||
|
<li><Link href="/about">About Us</Link></li>
|
||||||
|
<li><Link href="/contact">Contact Us</Link></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="footer-section">
|
||||||
|
<h3 className="footer-heading">Contact</h3>
|
||||||
|
<ul className="footer-links footer-contact">
|
||||||
|
<li>(403) 123-4567</li>
|
||||||
|
<li>support@leonspetstore.com</li>
|
||||||
|
<li>123 Street Street, Calgary, Alberta, Canada</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="footer-bottom">
|
||||||
|
<p>© {new Date().getFullYear()} Leon's Pet Store. All rights reserved.</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ export default function DisplayNav() {
|
|||||||
const { itemCount, selectedStoreId, setStoreId } = useCart();
|
const { itemCount, selectedStoreId, setStoreId } = useCart();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [stores, setStores] = useState([]);
|
const [stores, setStores] = useState([]);
|
||||||
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!token) return;
|
if (!token) return;
|
||||||
@@ -26,27 +27,35 @@ export default function DisplayNav() {
|
|||||||
function handleLogout() {
|
function handleLogout() {
|
||||||
logout();
|
logout();
|
||||||
router.push("/");
|
router.push("/");
|
||||||
|
setMenuOpen(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeMenu() {
|
||||||
|
setMenuOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className="navbar">
|
<nav className="navbar">
|
||||||
<Image
|
<Link href="/" onClick={closeMenu}>
|
||||||
className="mx-3"
|
<Image
|
||||||
src="/logo_simple.png"
|
className="mx-3"
|
||||||
alt="store_logo"
|
src="/logo_simple.png"
|
||||||
width={50}
|
alt="store_logo"
|
||||||
height={50}
|
width={50}
|
||||||
id="logo"
|
height={50}
|
||||||
/>
|
id="logo"
|
||||||
|
/>
|
||||||
|
</Link>
|
||||||
|
|
||||||
|
{/* Desktop: inline links + auth */}
|
||||||
<div className="nav-links">
|
<div className="nav-links">
|
||||||
<Link href="/" className="nav-link">Home</Link>
|
<Link href="/" className="nav-link">Home</Link>
|
||||||
<Link href="/adopt" className="nav-link">Adopt a Pet</Link>
|
<Link href="/adopt" className="nav-link">Adopt</Link>
|
||||||
<Link href="/products" className="nav-link">Online Store</Link>
|
<Link href="/products" className="nav-link">Store</Link>
|
||||||
<Link href="/appointments" className="nav-link">Schedule an Appointment</Link>
|
<Link href="/appointments" className="nav-link">Appointments</Link>
|
||||||
<Link href="/ai-chat" className="nav-link">AI Assistant</Link>
|
<Link href="/ai-chat" className="nav-link">Help</Link>
|
||||||
<Link href="/contact" className="nav-link">Contact Us</Link>
|
<Link href="/contact" className="nav-link">Contact</Link>
|
||||||
<Link href="/about" className="nav-link">About Us</Link>
|
<Link href="/about" className="nav-link">About</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="nav-auth">
|
<div className="nav-auth">
|
||||||
@@ -77,7 +86,7 @@ export default function DisplayNav() {
|
|||||||
{loading ? null : user ? (
|
{loading ? null : user ? (
|
||||||
<>
|
<>
|
||||||
<Link href="/profile" className="nav-link nav-greeting">
|
<Link href="/profile" className="nav-link nav-greeting">
|
||||||
Hello, {user.fullName || user.username}
|
Hello, {(user.fullName || user.username).split(" ")[0]}
|
||||||
</Link>
|
</Link>
|
||||||
<button type="button" className="nav-logout-btn" onClick={handleLogout}>
|
<button type="button" className="nav-logout-btn" onClick={handleLogout}>
|
||||||
Log Out
|
Log Out
|
||||||
@@ -90,6 +99,74 @@ export default function DisplayNav() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Mobile: cart icon + hamburger always in topbar */}
|
||||||
|
<div className="nav-mobile-bar">
|
||||||
|
{user && (
|
||||||
|
<Link href="/cart" className="nav-cart-btn" aria-label="Cart" onClick={closeMenu}>
|
||||||
|
🛒
|
||||||
|
{itemCount > 0 && (
|
||||||
|
<span className="nav-cart-badge">{itemCount > 99 ? "99+" : itemCount}</span>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
<button
|
||||||
|
className={`nav-hamburger${menuOpen ? " nav-hamburger--open" : ""}`}
|
||||||
|
aria-label="Toggle navigation menu"
|
||||||
|
aria-expanded={menuOpen}
|
||||||
|
onClick={() => setMenuOpen((o) => !o)}
|
||||||
|
>
|
||||||
|
<span />
|
||||||
|
<span />
|
||||||
|
<span />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Mobile dropdown drawer */}
|
||||||
|
{menuOpen && (
|
||||||
|
<div className="nav-drawer">
|
||||||
|
<Link href="/" className="nav-drawer-link" onClick={closeMenu}>Home</Link>
|
||||||
|
<Link href="/adopt" className="nav-drawer-link" onClick={closeMenu}>Adopt</Link>
|
||||||
|
<Link href="/products" className="nav-drawer-link" onClick={closeMenu}>Store</Link>
|
||||||
|
<Link href="/appointments" className="nav-drawer-link" onClick={closeMenu}>Appointments</Link>
|
||||||
|
<Link href="/ai-chat" className="nav-drawer-link" onClick={closeMenu}>Help</Link>
|
||||||
|
<Link href="/contact" className="nav-drawer-link" onClick={closeMenu}>Contact</Link>
|
||||||
|
<Link href="/about" className="nav-drawer-link" onClick={closeMenu}>About</Link>
|
||||||
|
|
||||||
|
<div className="nav-drawer-divider" />
|
||||||
|
|
||||||
|
{stores.length > 0 && (
|
||||||
|
<select
|
||||||
|
className="nav-store-select nav-store-select--drawer"
|
||||||
|
value={selectedStoreId ?? ""}
|
||||||
|
onChange={(e) => { setStoreId(e.target.value || null); closeMenu(); }}
|
||||||
|
>
|
||||||
|
<option value="">All Stores</option>
|
||||||
|
{stores.map((s) => (
|
||||||
|
<option key={s.storeId} value={s.storeId}>
|
||||||
|
{s.storeName}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{loading ? null : user ? (
|
||||||
|
<>
|
||||||
|
<Link href="/profile" className="nav-drawer-link" onClick={closeMenu}>
|
||||||
|
My Profile ({user.fullName || user.username})
|
||||||
|
</Link>
|
||||||
|
<button type="button" className="nav-logout-btn nav-logout-btn--drawer" onClick={handleLogout}>
|
||||||
|
Log Out
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Link href="/login" className="nav-drawer-link" onClick={closeMenu}>Log In</Link>
|
||||||
|
<Link href="/register" className="nav-drawer-link nav-drawer-link--register" onClick={closeMenu}>Register</Link>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,35 @@
|
|||||||
import Link from "next/link";
|
"use client";
|
||||||
|
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useAuth } from "@/context/AuthContext";
|
||||||
|
import { useCart } from "@/context/CartContext";
|
||||||
|
|
||||||
|
export default function ProductProfile({ prodId, prodName, categoryName, prodDesc, prodPrice, imageUrl }) {
|
||||||
|
const { user } = useAuth();
|
||||||
|
const { addItem, selectedStoreId } = useCart();
|
||||||
|
|
||||||
|
const [quantity, setQuantity] = useState(1);
|
||||||
|
const [adding, setAdding] = useState(false);
|
||||||
|
const [feedback, setFeedback] = useState(null); // { type: "success"|"error", message }
|
||||||
|
|
||||||
|
function changeQty(delta) {
|
||||||
|
setQuantity((q) => Math.max(1, q + delta));
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleAddToCart() {
|
||||||
|
setAdding(true);
|
||||||
|
setFeedback(null);
|
||||||
|
try {
|
||||||
|
await addItem(prodId, quantity);
|
||||||
|
setFeedback({ type: "success", message: `${quantity} × ${prodName} added to cart!` });
|
||||||
|
setQuantity(1);
|
||||||
|
} catch (err) {
|
||||||
|
setFeedback({ type: "error", message: err.message ?? "Failed to add to cart." });
|
||||||
|
} finally {
|
||||||
|
setAdding(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function ProductProfile({ prodName, categoryName, prodDesc, prodPrice, imageUrl }) {
|
|
||||||
return (
|
return (
|
||||||
<div className="pet-detail-card">
|
<div className="pet-detail-card">
|
||||||
<div className="pet-detail-image-wrapper">
|
<div className="pet-detail-image-wrapper">
|
||||||
@@ -36,6 +65,57 @@ export default function ProductProfile({ prodName, categoryName, prodDesc, prodP
|
|||||||
<span className="pet-detail-value">{prodDesc ?? "—"}</span>
|
<span className="pet-detail-value">{prodDesc ?? "—"}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="pet-detail-cta">
|
||||||
|
{!user ? (
|
||||||
|
<p className="pet-detail-cta-text">
|
||||||
|
<a href="/login" className="appt-link">Log in</a> to purchase this item.
|
||||||
|
</p>
|
||||||
|
) : !selectedStoreId ? (
|
||||||
|
<p className="pet-detail-cta-text">
|
||||||
|
Select a store from the navigation bar to add items to your cart.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="product-qty-row">
|
||||||
|
<span className="product-qty-label">Quantity</span>
|
||||||
|
<div className="product-qty-controls">
|
||||||
|
<button
|
||||||
|
className="cart-qty-btn"
|
||||||
|
onClick={() => changeQty(-1)}
|
||||||
|
disabled={quantity <= 1 || adding}
|
||||||
|
aria-label="Decrease quantity"
|
||||||
|
>
|
||||||
|
−
|
||||||
|
</button>
|
||||||
|
<span className="cart-qty-val">{quantity}</span>
|
||||||
|
<button
|
||||||
|
className="cart-qty-btn"
|
||||||
|
onClick={() => changeQty(1)}
|
||||||
|
disabled={adding}
|
||||||
|
aria-label="Increase quantity"
|
||||||
|
>
|
||||||
|
+
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
className="product-add-to-cart-btn"
|
||||||
|
onClick={handleAddToCart}
|
||||||
|
disabled={adding}
|
||||||
|
>
|
||||||
|
{adding ? "Adding…" : "Add to Cart"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{feedback && (
|
||||||
|
<p className={`product-cart-feedback product-cart-feedback--${feedback.type}`}>
|
||||||
|
{feedback.message}
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
apiClearCart,
|
apiClearCart,
|
||||||
apiApplyCoupon,
|
apiApplyCoupon,
|
||||||
apiCheckout,
|
apiCheckout,
|
||||||
|
apiCancelCheckout,
|
||||||
} from "@/lib/cartApi";
|
} from "@/lib/cartApi";
|
||||||
|
|
||||||
const CartContext = createContext(null);
|
const CartContext = createContext(null);
|
||||||
@@ -133,6 +134,15 @@ export function CartProvider({ children }) {
|
|||||||
[token, selectedStoreId]
|
[token, selectedStoreId]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const cancelCheckout = useCallback(
|
||||||
|
async () => {
|
||||||
|
if (!token || !selectedStoreId) return;
|
||||||
|
await apiCancelCheckout(token, selectedStoreId);
|
||||||
|
await refreshCart();
|
||||||
|
},
|
||||||
|
[token, selectedStoreId, refreshCart]
|
||||||
|
);
|
||||||
|
|
||||||
const itemCount = cart?.items?.reduce((sum, i) => sum + i.quantity, 0) ?? 0;
|
const itemCount = cart?.items?.reduce((sum, i) => sum + i.quantity, 0) ?? 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -150,6 +160,7 @@ export function CartProvider({ children }) {
|
|||||||
clearCart,
|
clearCart,
|
||||||
applyCoupon,
|
applyCoupon,
|
||||||
checkout,
|
checkout,
|
||||||
|
cancelCheckout,
|
||||||
refreshCart,
|
refreshCart,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -91,3 +91,12 @@ export async function apiCompleteCheckout(token, paymentIntentId) {
|
|||||||
|
|
||||||
return handleResponse(res);
|
return handleResponse(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function apiCancelCheckout(token, storeId) {
|
||||||
|
const res = await fetch(`${BASE}/checkout/cancel?storeId=${storeId}`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: authHeaders(token),
|
||||||
|
});
|
||||||
|
|
||||||
|
return handleResponse(res);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user