This commit is contained in:
@@ -90,14 +90,17 @@ export default function DeliveryScreen() {
|
||||
weeks: LoginHistoryWeek[];
|
||||
} | null>(null);
|
||||
const [loginHistoryLoading, setLoginHistoryLoading] = useState(false);
|
||||
const loginHistoryRequestRef = useRef(0);
|
||||
|
||||
const fetchLoginHistory = async (
|
||||
username: string,
|
||||
year: number,
|
||||
month: number,
|
||||
) => {
|
||||
const requestId = ++loginHistoryRequestRef.current;
|
||||
setLoginHistoryLoading(true);
|
||||
const res = await getLivreurLoginHistory(username, year, month);
|
||||
if (requestId !== loginHistoryRequestRef.current) return;
|
||||
setLoginHistoryModal({
|
||||
username,
|
||||
year: res.year,
|
||||
@@ -113,7 +116,7 @@ export default function DeliveryScreen() {
|
||||
};
|
||||
|
||||
const changeLoginHistoryMonth = (delta: number) => {
|
||||
if (!loginHistoryModal) return;
|
||||
if (!loginHistoryModal || loginHistoryLoading) return;
|
||||
let year = loginHistoryModal.year;
|
||||
let month = loginHistoryModal.month + delta;
|
||||
if (month < 1) {
|
||||
@@ -123,6 +126,13 @@ export default function DeliveryScreen() {
|
||||
month = 1;
|
||||
year += 1;
|
||||
}
|
||||
const now = new Date();
|
||||
if (
|
||||
year > now.getFullYear() ||
|
||||
(year === now.getFullYear() && month > now.getMonth() + 1)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
fetchLoginHistory(loginHistoryModal.username, year, month);
|
||||
};
|
||||
|
||||
@@ -1159,54 +1169,88 @@ export default function DeliveryScreen() {
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
marginBottom: spacing.m,
|
||||
}}
|
||||
>
|
||||
<TouchableOpacity
|
||||
onPress={() => changeLoginHistoryMonth(-1)}
|
||||
>
|
||||
<Ionicons
|
||||
name="chevron-back"
|
||||
size={20}
|
||||
color={colors.textPrimary}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
<Text
|
||||
style={{
|
||||
color: colors.textWhite,
|
||||
fontWeight: "700",
|
||||
fontSize: fontSize.md,
|
||||
}}
|
||||
>
|
||||
{loginHistoryModal &&
|
||||
new Date(
|
||||
loginHistoryModal.year,
|
||||
loginHistoryModal.month - 1,
|
||||
1,
|
||||
)
|
||||
.toLocaleDateString("fr-FR", {
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
})
|
||||
.replace(/^./, (c) =>
|
||||
c.toUpperCase(),
|
||||
)}
|
||||
</Text>
|
||||
<TouchableOpacity
|
||||
onPress={() => changeLoginHistoryMonth(1)}
|
||||
>
|
||||
<Ionicons
|
||||
name="chevron-forward"
|
||||
size={20}
|
||||
color={colors.textPrimary}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
{(() => {
|
||||
const now = new Date();
|
||||
const isCurrentMonth =
|
||||
!!loginHistoryModal &&
|
||||
loginHistoryModal.year ===
|
||||
now.getFullYear() &&
|
||||
loginHistoryModal.month ===
|
||||
now.getMonth() + 1;
|
||||
const canGoBack = !loginHistoryLoading;
|
||||
const canGoForward =
|
||||
!loginHistoryLoading && !isCurrentMonth;
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
marginBottom: spacing.m,
|
||||
}}
|
||||
>
|
||||
<TouchableOpacity
|
||||
disabled={!canGoBack}
|
||||
onPress={() =>
|
||||
changeLoginHistoryMonth(-1)
|
||||
}
|
||||
hitSlop={8}
|
||||
>
|
||||
<Ionicons
|
||||
name="chevron-back"
|
||||
size={20}
|
||||
color={
|
||||
canGoBack
|
||||
? colors.textPrimary
|
||||
: colors.textMuted
|
||||
}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
<Text
|
||||
style={{
|
||||
color: colors.textWhite,
|
||||
fontWeight: "700",
|
||||
fontSize: fontSize.md,
|
||||
}}
|
||||
>
|
||||
{loginHistoryModal &&
|
||||
new Date(
|
||||
loginHistoryModal.year,
|
||||
loginHistoryModal.month -
|
||||
1,
|
||||
1,
|
||||
)
|
||||
.toLocaleDateString(
|
||||
"fr-FR",
|
||||
{
|
||||
month: "long",
|
||||
year: "numeric",
|
||||
},
|
||||
)
|
||||
.replace(/^./, (c) =>
|
||||
c.toUpperCase(),
|
||||
)}
|
||||
</Text>
|
||||
<TouchableOpacity
|
||||
disabled={!canGoForward}
|
||||
onPress={() =>
|
||||
changeLoginHistoryMonth(1)
|
||||
}
|
||||
hitSlop={8}
|
||||
>
|
||||
<Ionicons
|
||||
name="chevron-forward"
|
||||
size={20}
|
||||
color={
|
||||
canGoForward
|
||||
? colors.textPrimary
|
||||
: colors.textMuted
|
||||
}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
})()}
|
||||
|
||||
{loginHistoryLoading ? (
|
||||
<Text style={styles.ratingsEmpty}>
|
||||
|
||||
Reference in New Issue
Block a user