Overview
The Damacana Limits API manages time-based restrictions for water jug orders, including cutoff times and product identification.
Source: src/config/damacanaLimits.js
Functions
checkCartForDamacana()
Checks if the cart contains damacana items and validates whether damacana orders are allowed at the current time.
import { checkCartForDamacana } from '@/config/damacanaLimits' ;
import { useCart } from '@/context/CartContext' ;
const CartSummary = () => {
const { items } = useCart ();
const damacanaCheck = checkCartForDamacana ( items );
if ( damacanaCheck . hasDamacana && ! damacanaCheck . isAllowed ) {
return < Alert > { damacanaCheck . message } </ Alert > ;
}
return < CheckoutButton /> ;
};
Array of cart items. Each item must have an id property
Damacana validation result object
Show Return Object Structure
Whether the cart contains any damacana items
Array of damacana items in cart (only present if hasDamacana is true)
Whether damacana orders are allowed at the current time
Error message if not allowed, null if allowed
// No damacana items
{ hasDamacana : false , isAllowed : true , message : null }
// Has damacana, allowed
{
hasDamacana : true ,
damacanaItems : [{ id: 11 , name: "19L Damacana" , ... }],
isAllowed : true ,
message : null
}
// Has damacana, not allowed
{
hasDamacana : true ,
damacanaItems : [{ id: 11 , name: "19L Damacana" , ... }],
isAllowed : false ,
message : "Damacana siparişleri 19:00'dan sonra alınmamaktadır"
}
isDamacana()
Checks if a product ID matches the damacana pattern.
import { isDamacana } from '@/config/damacanaLimits' ;
const productId = 11 ;
if ( isDamacana ( productId )) {
console . log ( 'This is a damacana product' );
}
Returns true if the ID matches the damacana pattern (ends with 1)
Uses regex /1$/ to match IDs ending with 1:
Damacana IDs: 11, 21, 31, 41, 51, 61, 71, 81
Non-damacana: 12, 23, 34, etc.
Console logs result for debugging: "Damacana Check: ID 11 -> DAMACANA"
isDamacanaOrderAllowed()
Checks whether damacana orders are currently allowed based on time restrictions.
import { isDamacanaOrderAllowed } from '@/config/damacanaLimits' ;
const checkDamacana = () => {
const result = isDamacanaOrderAllowed ();
if ( ! result . isAllowed ) {
alert ( result . message );
}
};
Show Return Object Structure
Whether damacana orders are allowed
Error message if not allowed, null if allowed
Returns { isAllowed: true } if enabled is false or testMode is true
Checks if current time is in restricted period (after cutoff or before start time)
Uses different cutoff times for weekdays vs weekends (if weekendEnabled is true)
Extensive console logging for debugging time calculations
getDamacanaOrderHoursText()
Returns formatted string of damacana order hours.
import { getDamacanaOrderHoursText } from '@/config/damacanaLimits' ;
const hours = getDamacanaOrderHoursText ();
console . log ( hours ); // "08:30 - 19:00"
// or with weekend hours:
// "Hafta içi: 08:30 - 19:00, Hafta sonu: 08:30 - 18:00"
Formatted damacana order hours. Includes separate weekend hours if weekendEnabled is true
Configuration
DAMACANA_LIMITS
Damacana restrictions configuration object.
import { DAMACANA_LIMITS } from '@/config/damacanaLimits' ;
console . log ( DAMACANA_LIMITS . cutoffHour ); // 19
Show Configuration Properties
Hour when damacana orders stop being accepted (24-hour format)
Minute component of cutoff time
Hour when damacana orders start being accepted next day (24-hour format)
Minute component of start time
Whether damacana time restrictions are enabled
Message shown when orders are not allowed. Supports {cutoffTime} and {startTime} placeholders
If true, time restrictions are disabled
Regex pattern to identify damacana products by ID
Weekend cutoff hour (1 hour earlier than weekday)
Whether to use different hours for weekends
ID Pattern Matching
Damacana products are identified by IDs ending with 1:
// Damacana products (ID ends with 1)
11 → 19 L Damacana ✓
21 → 19 L Damacana ( 2 pack ) ✓
31 → 19 L Damacana ( 3 pack ) ✓
41 , 51 , 61 , 71 , 81 → All damacanas ✓
// Non-damacana products
12 → 6 x1 .5 L Pack ✗
23 → 12 x0 .5 L Pack ✗
The pattern uses regex: /1$/ which matches any ID ending with the digit 1.
Usage Example
import {
checkCartForDamacana ,
isDamacana ,
getDamacanaOrderHoursText
} from '@/config/damacanaLimits' ;
import { useCart } from '@/context/CartContext' ;
const OrderRestrictionAlert = () => {
const { items } = useCart ();
const damacanaCheck = checkCartForDamacana ( items );
if ( ! damacanaCheck . hasDamacana ) {
return null ; // No damacana in cart
}
if ( ! damacanaCheck . isAllowed ) {
return (
< Alert severity = "warning" >
< p > { damacanaCheck . message } </ p >
< p > Damacana sipariş saatleri: { getDamacanaOrderHoursText () } </ p >
< p > Damacana ürünleri: { damacanaCheck . damacanaItems . length } adet </ p >
</ Alert >
);
}
return null ;
};
Time Logic
The damacana restriction creates a blocked time window:
Blocked period: After cutoff time until next day’s start time
Allowed period: Start time to cutoff time
Example with default settings:
Blocked: 19:00 - 08:30 (next day)
Allowed: 08:30 - 19:00
The function handles midnight crossing automatically.