diff --git a/data.json b/data.json index d28cfc9..92aecbd 100644 --- a/data.json +++ b/data.json @@ -184,7 +184,7 @@ "id": 1, "email": "myemail@mail.com", "password": "12345678", - "expirationDate": null + "expirationDate": "2025-01-12T20:22:19.846Z" }, { "id": 2, diff --git a/src/assets/main-page/posters/BetterCallSaul.jpg b/src/assets/main-page/posters/BetterCallSaul.jpg deleted file mode 100644 index 7b0f1fd..0000000 Binary files a/src/assets/main-page/posters/BetterCallSaul.jpg and /dev/null differ diff --git a/src/components/user/hooks/UserSubscriptionHook.js b/src/components/user/hooks/UserSubscriptionHook.js deleted file mode 100644 index 3dcaf7e..0000000 --- a/src/components/user/hooks/UserSubscriptionHook.js +++ /dev/null @@ -1,97 +0,0 @@ -import toast from 'react-hot-toast'; -import { useEffect, useState } from 'react'; -import UsersApiService from '../../authentification/service/UsersApiService'; - -const useUserSubscription = (userId) => { - const [subscriptionRefresh, setSubscriptionRefresh] = useState(false); - const [subscriptionInitialized, setSubscriptionInitialized] = useState(false); - const [currentUser, setCurrentUser] = useState({}); - const [isSubscriptionActive, setIsSubscriptionActive] = useState(false); - const handleSubscriptionChange = () => setSubscriptionRefresh(!subscriptionRefresh); - - const handleChange = async (userObject) => { - if (userId === -1) { - return; - } - - await UsersApiService.update(userId, userObject); - - handleSubscriptionChange(); - toast.success('Статус подписки успешно обновлен'); - }; - - const getExpirationDate = () => { - return currentUser.expirationDate; - }; - - const getExpirationDateFormatted = () => { - if (currentUser.expirationDate === null) { - return 'идёт отмена...'; - } - - const timestamp = Date.parse(currentUser.expirationDate); - const expirationDate = new Date(timestamp); - - return expirationDate.toLocaleString('ru-RU').split(', ')[0]; - }; - - const hasActiveSubscription = () => { - if (currentUser.expirationDate === null) { - return false; - } - - const currentDate = new Date().getTime(); - const expirationDate = Date.parse(getExpirationDate()); - - return currentDate <= expirationDate; - }; - - const setSubscription = (newExpirationDate) => { - currentUser.expirationDate = newExpirationDate.toISOString(); - handleChange(currentUser); - }; - - const cancelSubscription = () => { - currentUser.expirationDate = null; - - handleChange(currentUser); - }; - - const refreshUserData = async (id) => { - if (id === -1) { - return; - } - - const data = await UsersApiService.get(id); - - localStorage.setItem('currentUser', JSON.stringify(data)); - setCurrentUser(data); - }; - - useEffect(() => { - refreshUserData(userId); - - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [subscriptionRefresh]); - - useEffect(() => { - if (Object.keys(currentUser).length === 0) { - return; - } - - setIsSubscriptionActive(hasActiveSubscription()); - setSubscriptionInitialized(true); - - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [currentUser]); - - return { - subscriptionInitialized, - isSubscriptionActive, - getExpirationDateFormatted, - cancelSubscription, - setSubscription, - }; -}; - -export default useUserSubscription; diff --git a/src/pages/PageLogin.jsx b/src/pages/PageLogin.jsx index 5816492..97da314 100644 --- a/src/pages/PageLogin.jsx +++ b/src/pages/PageLogin.jsx @@ -3,7 +3,7 @@ import { } from 'react-bootstrap'; import { - PersonCircle, EnvelopeFill, LockFill, EyeFill, + PersonCircle, EnvelopeFill, LockFill, } from 'react-bootstrap-icons'; import { useState } from 'react'; @@ -26,8 +26,6 @@ const PageLogin = () => { await handleSubmit(event); }; - // - return ( <>
diff --git a/Отчет лаб5.docx b/Отчет лаб5.docx index 87c8665..100d3b4 100644 Binary files a/Отчет лаб5.docx and b/Отчет лаб5.docx differ