Replace entire repo content with correct code from /root/shahikitchen-website/
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
/** Port: external messaging channel (WhatsApp, SMS, etc.). */
|
||||
export interface MessagingGateway {
|
||||
openWhatsApp(message: string): void;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
import type { DeliveryInquiryDetails, PickupInquiryDetails } from '@/domain/cart/inquiry';
|
||||
import type { BookingDetails } from '@/domain/booking/entities';
|
||||
import { isBookingComplete } from '@/domain/booking/validation';
|
||||
import type { Language } from '@/domain/language/entities';
|
||||
import {
|
||||
calculateOrderTotal,
|
||||
formatOrderLinesForInquiry,
|
||||
formatOrderLinesForMessage,
|
||||
type OrderLine,
|
||||
} from '@/domain/shared/order-line';
|
||||
import { PICKUP_LEAD_TIME_MINUTES } from '@/domain/shared/constants';
|
||||
|
||||
export interface CartInquiryCopy {
|
||||
pickupIntro: string;
|
||||
deliveryIntro: string;
|
||||
messageTotal: string;
|
||||
messageName: string;
|
||||
messagePhone: string;
|
||||
messageAddress: string;
|
||||
messagePreferredTime: string;
|
||||
deliverySwishNote: string;
|
||||
}
|
||||
|
||||
/** @deprecated Legacy cart copy — kept for any remaining references */
|
||||
export interface CartDrawerCopy {
|
||||
messageHello: string;
|
||||
messageIntro: string;
|
||||
messageAddress: string;
|
||||
messageConfirm: string;
|
||||
messageTotal: string;
|
||||
messageThanks: string;
|
||||
}
|
||||
|
||||
export interface BookingLocationCopy {
|
||||
askim: string;
|
||||
backaplan: string;
|
||||
}
|
||||
|
||||
export function getSuggestedPickupTime(language: Language, from: Date = new Date()): string {
|
||||
const suggested = new Date(from.getTime() + PICKUP_LEAD_TIME_MINUTES * 60 * 1000);
|
||||
const timeLocale =
|
||||
language === 'sv' ? 'sv-SE' :
|
||||
language === 'ar' ? 'ar-SA' :
|
||||
language === 'tr' ? 'tr-TR' :
|
||||
'en-GB';
|
||||
return suggested.toLocaleTimeString(timeLocale, { hour: '2-digit', minute: '2-digit' });
|
||||
}
|
||||
|
||||
export function buildPickupInquiryMessage(
|
||||
items: OrderLine[],
|
||||
details: PickupInquiryDetails,
|
||||
copy: CartInquiryCopy,
|
||||
): string | null {
|
||||
if (items.length === 0) return null;
|
||||
|
||||
const lines = formatOrderLinesForInquiry(items);
|
||||
const total = calculateOrderTotal(items);
|
||||
|
||||
return `${copy.pickupIntro}
|
||||
${lines}
|
||||
${copy.messageTotal}: ${total} kr
|
||||
${copy.messageName}: ${details.name.trim()}
|
||||
${copy.messagePhone}: ${details.phone.trim()}`;
|
||||
}
|
||||
|
||||
export function buildDeliveryInquiryMessage(
|
||||
items: OrderLine[],
|
||||
details: DeliveryInquiryDetails,
|
||||
copy: CartInquiryCopy,
|
||||
): string | null {
|
||||
if (items.length === 0) return null;
|
||||
|
||||
const lines = formatOrderLinesForInquiry(items);
|
||||
const total = calculateOrderTotal(items);
|
||||
|
||||
return `${copy.deliveryIntro}
|
||||
${lines}
|
||||
${copy.messageTotal}: ${total} kr
|
||||
${copy.messageName}: ${details.name.trim()}
|
||||
${copy.messageAddress}: ${details.address.trim()}
|
||||
${copy.messagePhone}: ${details.phone.trim()}
|
||||
${copy.messagePreferredTime}: ${details.preferredTime.trim()}
|
||||
${copy.deliverySwishNote}`;
|
||||
}
|
||||
|
||||
export function buildBookingWhatsAppMessage(
|
||||
booking: BookingDetails,
|
||||
preOrder: OrderLine[],
|
||||
locationCopy: BookingLocationCopy
|
||||
): string | null {
|
||||
if (!isBookingComplete(booking)) return null;
|
||||
|
||||
const locationLabel =
|
||||
booking.location === 'askim' ? locationCopy.askim : locationCopy.backaplan;
|
||||
|
||||
const itemsText =
|
||||
preOrder.length > 0
|
||||
? formatOrderLinesForMessage(preOrder).replace(/ — /g, ' — ')
|
||||
: 'None';
|
||||
|
||||
const totalText =
|
||||
preOrder.length > 0 ? `\nPre-order total: ${calculateOrderTotal(preOrder)} kr\n` : '';
|
||||
|
||||
return `Hello Shahi Kitchen 👋
|
||||
|
||||
Table Reservation Inquiry:
|
||||
|
||||
Name: ${booking.name}
|
||||
Phone: ${booking.phone}
|
||||
Email: ${booking.email || 'N/A'}
|
||||
Location: ${locationLabel}
|
||||
Date: ${booking.date}
|
||||
Time: ${booking.time}
|
||||
Guests: ${booking.guests}
|
||||
Special Requests: ${booking.notes || 'None'}
|
||||
|
||||
Pre-ordered items:
|
||||
${itemsText}${totalText}
|
||||
Please confirm table availability and pre-order.
|
||||
|
||||
Thank you!`;
|
||||
}
|
||||
Reference in New Issue
Block a user