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