- Implemented CartContext for managing cart state, including adding, removing, and updating items. - Added CartDrawer component to display cart items. - Updated AppHeader to include cart item count. - Enhanced welcome page with new layout, improved product image handling, and updated call-to-action buttons. - Refactored homepage data types to accommodate new features and removed unused properties.
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
export function formatNumber(
|
|
num: number,
|
|
options?: Intl.NumberFormatOptions,
|
|
): string {
|
|
return new Intl.NumberFormat('id-ID', options).format(num);
|
|
}
|
|
|
|
export function formatWhatsAppPhone(phone: string): string {
|
|
const digits = phone.replace(/\D/g, '');
|
|
|
|
if (digits.startsWith('62')) {
|
|
return digits;
|
|
}
|
|
|
|
if (digits.startsWith('0')) {
|
|
return '62' + digits.slice(1);
|
|
}
|
|
|
|
return '62' + digits;
|
|
}
|
|
|
|
export type DateFormatStyle = 'full' | 'short' | 'datetime';
|
|
|
|
export function formatDate(dateString: string, style: DateFormatStyle = 'full'): string {
|
|
const date = new Date(dateString);
|
|
|
|
const datePart = date.toLocaleDateString('id-ID', {
|
|
day: '2-digit',
|
|
month: style === 'short' ? 'short' : 'long',
|
|
year: 'numeric',
|
|
});
|
|
|
|
if (style === 'short') {
|
|
return datePart;
|
|
}
|
|
|
|
const timePart = date.toLocaleTimeString('id-ID', {
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
});
|
|
|
|
return `${datePart} ${timePart}`;
|
|
}
|
|
|
|
export function formatShortDate(dateString: string): string {
|
|
return formatDate(dateString, 'short');
|
|
}
|
|
|
|
export function formatDateTime(dateString: string): string {
|
|
return formatDate(dateString, 'datetime');
|
|
}
|