4.1 KiB
4.1 KiB
Duplicate Feature Updates
Changes Made
✅ Permission Updates
- Universal Access: All users (auth level 1+) can now duplicate ANY report, not just their own
- Date Restriction: Added date validation - reports older than the day before current date cannot be duplicated
- User Assignment: Duplicated reports are always assigned to the current user (regardless of original owner)
✅ Date Validation Logic
// Client-side validation
const reportDate = new Date(report.createdDate);
const dayBeforeToday = new Date();
dayBeforeToday.setDate(dayBeforeToday.getDate() - 1);
dayBeforeToday.setHours(0, 0, 0, 0); // Set to start of day
if (reportDate < dayBeforeToday) {
return false; // Cannot duplicate
}
✅ Server-side Validation
// Server-side validation in duplicate action
const reportDate = new Date(originalReport.createdDate);
const dayBeforeToday = new Date();
dayBeforeToday.setDate(dayBeforeToday.getDate() - 1);
dayBeforeToday.setHours(0, 0, 0, 0);
if (reportDate < dayBeforeToday) {
return json({ errors: { form: "Cannot duplicate reports older than yesterday" } }, { status: 400 });
}
✅ UI Improvements
Desktop Table View
- Active Button: Green "Duplicate" button for eligible reports
- Disabled State: Gray "Duplicate" text with tooltip for old reports
- Tooltip: "Cannot duplicate reports older than yesterday"
Mobile Card View
- Active Button: Full-width green button for eligible reports
- Disabled State: Gray disabled button with "(Too Old)" indicator
- Clear Messaging: Shows why duplication is not available
✅ Business Rules
Who Can Duplicate
- ✅ Level 1 Users: Can duplicate any report (within date range)
- ✅ Level 2+ Users: Can duplicate any report (within date range)
- ✅ Cross-User: Users can duplicate reports created by other users
When Can Duplicate
- ✅ Today's Reports: Can be duplicated
- ✅ Yesterday's Reports: Can be duplicated
- ❌ Older Reports: Cannot be duplicated (day before yesterday and older)
What Gets Duplicated
- ✅ All operational data (locations, equipment, pipeline, etc.)
- ✅ Time sheet entries
- ✅ Notes
- ❌ Stoppages (excluded)
- ❌ Original employee assignment (assigned to current user)
✅ Error Messages
New Error Message
"Cannot duplicate reports older than yesterday"
Existing Error Messages
- "Cannot duplicate report - sheet is already complete with both day and night shifts"
- "Cannot duplicate report - night shift already exists for this date and location"
- "Failed to duplicate report"
✅ Use Cases
Primary Use Case
- Employee A creates a day shift report yesterday
- Employee B (different user) sees the report today
- Employee B clicks "Duplicate" to create a night shift
- System creates night shift assigned to Employee B
- Employee B can then customize the night shift as needed
Date Restriction Use Case
- User tries to duplicate a report from 3 days ago
- Duplicate button is disabled/grayed out
- Tooltip explains: "Cannot duplicate reports older than yesterday"
- Prevents duplication of stale operational data
✅ Benefits of Changes
- Improved Collaboration: Any user can duplicate any recent report
- Data Freshness: Prevents duplication of outdated operational data
- User Ownership: Duplicated reports belong to the duplicating user
- Clear Feedback: Visual indicators show when duplication is not available
- Operational Efficiency: Faster completion of report sheets by any team member
✅ Security Considerations
- Data Access: Users can see and duplicate any report (business requirement)
- Ownership: Duplicated reports are owned by the current user
- Date Validation: Prevents misuse of old operational data
- Sheet Integrity: Maintains proper sheet relationships and validation
The updated duplicate feature now provides better accessibility and collaboration while maintaining data integrity through date restrictions.