в привилегии добавлено поле о последнем дне
This commit is contained in:
parent
6ef0157afb
commit
b129058f3d
@ -9,6 +9,7 @@ import { clearAuthToken, getMessageFromFetchError } from "@frontend/kitui";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { useUserAccountFetcher } from "../../App";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import moment from "moment";
|
||||
|
||||
export default function AvailablePrivilege() {
|
||||
const user = useUserStore();
|
||||
@ -47,6 +48,19 @@ export default function AvailablePrivilege() {
|
||||
const quizUnlimTime = userPrivileges?.quizUnlimTime?.amount || 0;
|
||||
const quizCnt = userPrivileges?.quizCnt?.amount || 0;
|
||||
const squizHideBadge = userPrivileges?.squizHideBadge?.amount || 0;
|
||||
|
||||
//Где дни - amount - это на сколько дней выдан безлимит. т.е. не сколько осталось, а на сколько дней выдано
|
||||
function getCramps (amount: number, created_at: string) {
|
||||
if (created_at.length === 0) return 0
|
||||
const currentDate = moment()
|
||||
|
||||
return Number((moment(currentDate.add(amount, "days").diff(created_at)).unix() / 86400).toFixed(1))
|
||||
}
|
||||
const quizUnlimDays = getCramps(quizUnlimTime, userPrivileges?.quizUnlimTime?.created_at || "")
|
||||
const squizBadgeDays = getCramps(squizHideBadge, userPrivileges?.squizHideBadge?.created_at || "")
|
||||
|
||||
console.log(quizUnlimDays)
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
@ -65,7 +79,12 @@ export default function AvailablePrivilege() {
|
||||
<Typography variant={"body1"} sx={{ color: "#4D4D4D" }}>
|
||||
Безлимитные заявки:{" "}
|
||||
<strong>
|
||||
{quizUnlimTime} {declOfNum(quizUnlimTime, DayForm)}
|
||||
{
|
||||
quizUnlimDays > 0 && quizUnlimDays < 1 ?
|
||||
"последний день"
|
||||
:
|
||||
`${quizUnlimTime} ${declOfNum(Math.trunc(quizUnlimDays), DayForm)}`
|
||||
}
|
||||
</strong>
|
||||
</Typography>
|
||||
{quizCnt !== 0 && (
|
||||
@ -77,7 +96,12 @@ export default function AvailablePrivilege() {
|
||||
<Typography variant={"body1"} sx={{ color: "#4D4D4D" }}>
|
||||
Скрытие логотипа PenaQuiz:{" "}
|
||||
<strong>
|
||||
{squizHideBadge} {declOfNum(squizHideBadge, DayForm)}
|
||||
{
|
||||
squizBadgeDays > 0 && squizBadgeDays < 1 ?
|
||||
"последний день"
|
||||
:
|
||||
`${squizHideBadge} ${declOfNum(Math.trunc(squizBadgeDays), DayForm)}`
|
||||
}
|
||||
</strong>
|
||||
</Typography>
|
||||
)}
|
||||
|
Loading…
Reference in New Issue
Block a user