feat(frontend): automate day type selection and remove manual input
All checks were successful
Docker Build and Publish / build-and-push (push) Successful in 33s
All checks were successful
Docker Build and Publish / build-and-push (push) Successful in 33s
This commit is contained in:
@@ -39,12 +39,22 @@ const EntryForm = ({ onEntryAdded }) => {
|
|||||||
}
|
}
|
||||||
}, [duration, type, dayType, entryMode]);
|
}, [duration, type, dayType, entryMode]);
|
||||||
|
|
||||||
|
// Auto-detect Day Type based on Date
|
||||||
|
useEffect(() => {
|
||||||
|
if (!date) return;
|
||||||
|
// Parse date manually to avoid UTC conversion issues (use local noon)
|
||||||
|
const [y, m, d] = date.split('-').map(Number);
|
||||||
|
const checkDate = new Date(y, m - 1, d, 12, 0, 0);
|
||||||
|
const detected = detectDayType(checkDate);
|
||||||
|
setDayType(detected);
|
||||||
|
}, [date]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (entryMode === 'range' && type === 'standby') {
|
if (entryMode === 'range' && type === 'standby') {
|
||||||
const entries = generateStandbyEntries(date, dateEnd);
|
const entries = generateStandbyEntries(date, dateEnd);
|
||||||
let total = 0;
|
let total = 0;
|
||||||
entries.forEach(e => {
|
entries.forEach(e => {
|
||||||
const banked = calculateBankedHours(e.duration, e.type, e.dayType); // Should handle 16->2, 24->3 (if formula is correct)
|
const banked = calculateBankedHours(e.duration, e.type, e.dayType);
|
||||||
total += banked;
|
total += banked;
|
||||||
});
|
});
|
||||||
setBulkPreview({ count: entries.length, totalHours: total });
|
setBulkPreview({ count: entries.length, totalHours: total });
|
||||||
@@ -228,16 +238,12 @@ const EntryForm = ({ onEntryAdded }) => {
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-sm font-medium text-gray-700">{t('entry.day_type')}</label>
|
<label className="block text-sm font-medium text-gray-700">{t('entry.day_type')}</label>
|
||||||
<select
|
<input
|
||||||
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2"
|
type="text"
|
||||||
value={dayType}
|
readOnly
|
||||||
onChange={e => setDayType(e.target.value)}
|
className="mt-1 block w-full border border-gray-300 bg-gray-100 rounded-md shadow-sm p-2 text-gray-600 cursor-not-allowed"
|
||||||
>
|
value={t(`day.${dayType}`)}
|
||||||
<option value="workday">{t('day.workday')}</option>
|
/>
|
||||||
<option value="rest_day_1">{t('day.rest_day_1')}</option>
|
|
||||||
<option value="rest_day_2">{t('day.rest_day_2')}</option>
|
|
||||||
<option value="holiday">{t('day.holiday')}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user