| 1 |
/** |
| 2 |
* Day Conflict Dialog Component |
| 3 |
* Shows a confirmation dialog when a day number conflict is detected |
| 4 |
*/ |
| 5 |
|
| 6 |
import React from "react"; |
| 7 |
import { ConfirmationDialog } from "../ui/confirmation-dialog"; |
| 8 |
import { __ } from "../../lib/i18n"; |
| 9 |
|
| 10 |
interface DayConflictDialogProps { |
| 11 |
isOpen: boolean; |
| 12 |
conflictDayNumber: number | null; |
| 13 |
suggestedDayNumber: number | null; |
| 14 |
existingDayNumbers: number[]; |
| 15 |
isUpdateMode?: boolean; // true when updating an existing day, false when creating new |
| 16 |
onClose: () => void; |
| 17 |
onConfirm: () => void; |
| 18 |
} |
| 19 |
|
| 20 |
export const DayConflictDialog: React.FC<DayConflictDialogProps> = ({ |
| 21 |
isOpen, |
| 22 |
conflictDayNumber, |
| 23 |
suggestedDayNumber, |
| 24 |
existingDayNumbers, |
| 25 |
isUpdateMode = false, |
| 26 |
onClose, |
| 27 |
onConfirm, |
| 28 |
}) => { |
| 29 |
let message = ""; |
| 30 |
let title = ""; |
| 31 |
let confirmText = ""; |
| 32 |
|
| 33 |
if (isUpdateMode && conflictDayNumber !== null) { |
| 34 |
// Update mode: User is trying to change number to an existing day |
| 35 |
title = __("Replace Existing Day?", "yatra"); |
| 36 |
message = |
| 37 |
__("Day", "yatra") + |
| 38 |
` ${conflictDayNumber} ` + |
| 39 |
__( |
| 40 |
"already exists for this trip. Do you want to replace it with the current day's data?", |
| 41 |
"yatra", |
| 42 |
); |
| 43 |
confirmText = __("Yes, Replace Day", "yatra") + ` ${conflictDayNumber}`; |
| 44 |
} else if ( |
| 45 |
!isUpdateMode && |
| 46 |
conflictDayNumber !== null && |
| 47 |
suggestedDayNumber !== null && |
| 48 |
existingDayNumbers.length > 0 |
| 49 |
) { |
| 50 |
// Add mode: User is trying to create a day that already exists |
| 51 |
title = __("Day Number Already Exists", "yatra"); |
| 52 |
const existingDaysList = existingDayNumbers.join(", "); |
| 53 |
message = |
| 54 |
__("Day", "yatra") + |
| 55 |
` ${existingDaysList} ` + |
| 56 |
__("already exists for this trip. Do you want to use day", "yatra") + |
| 57 |
` ${suggestedDayNumber} ` + |
| 58 |
__("instead?", "yatra"); |
| 59 |
confirmText = __("Use Day", "yatra") + ` ${suggestedDayNumber}`; |
| 60 |
} else { |
| 61 |
// Fallback |
| 62 |
title = __("Day Number Already Exists", "yatra"); |
| 63 |
message = __("This day number already exists.", "yatra"); |
| 64 |
confirmText = __("OK", "yatra"); |
| 65 |
} |
| 66 |
|
| 67 |
return ( |
| 68 |
<ConfirmationDialog |
| 69 |
isOpen={isOpen} |
| 70 |
onClose={onClose} |
| 71 |
onConfirm={onConfirm} |
| 72 |
title={title} |
| 73 |
message={message} |
| 74 |
confirmText={confirmText} |
| 75 |
cancelText={__("Cancel", "yatra")} |
| 76 |
variant="warning" |
| 77 |
/> |
| 78 |
); |
| 79 |
}; |
| 80 |
|