diff --git a/.github/workflows/pr_closed_test.yml b/.github/workflows/pr_closed_test.yml index 23205c2b..082b4fe1 100644 --- a/.github/workflows/pr_closed_test.yml +++ b/.github/workflows/pr_closed_test.yml @@ -62,6 +62,8 @@ jobs: echo DEBUG=${{ secrets.TEST_DEBUG }} >> .env echo EMAIL_BACKEND_TYPE=${{ secrets.EMAIL_BACKEND_TYPE }} >> .env echo REACT_APP_SERVER_TYPE=${{ secrets.REACT_APP_SERVER_TYPE_TEST }} >> .env + echo YOOKASSA_CLIENT_ID=${{ secrets.YOOKASSA_CLIENT_ID }} >> .env + echo YOOKASSA_CLIENT_SECRET=${{ secrets.YOOKASSA_CLIENT_SECRET }} >> .env sudo docker-compose pull sudo docker-compose up -d diff --git a/src/hooks/useValidation.js b/src/hooks/useValidation.js index ebae6d43..f6dfcd2b 100644 --- a/src/hooks/useValidation.js +++ b/src/hooks/useValidation.js @@ -8,6 +8,7 @@ const useValidation = (value, validations, errorValidateMessage) => { const [minLengthError, setMinLengthError] = useState(false); const [maxLengthError, setMaxLengthError] = useState(false); const [regexError, setRegexError] = useState(false); + const [isZeroError, setIsZeroError] = useState(false); useEffect(() => { if (!validations.notEmpty && !value) { @@ -28,6 +29,9 @@ const useValidation = (value, validations, errorValidateMessage) => { case 'regex': validations[validation].test(value) ? setRegexError(false) : setRegexError(true); break; + case 'isZero': + parseInt(value, 10) === 0 ? setIsZeroError(true) : setIsZeroError(false); + break; default: break; } @@ -43,10 +47,12 @@ const useValidation = (value, validations, errorValidateMessage) => { setErrorText(errorValidateMessage.TOO_LONG); } else if (regexError) { setErrorText(errorValidateMessage.INVALID); + } else if (isZeroError) { + setErrorText(errorValidateMessage.IS_ZERO); } else { setErrorText(''); } - }, [emptyError, minLengthError, maxLengthError, regexError]); + }, [emptyError, minLengthError, maxLengthError, regexError, isZeroError]); return errorText; }; diff --git a/src/modules/AboutShelter/AboutShelter.jsx b/src/modules/AboutShelter/AboutShelter.jsx index 6dcb9f8a..2440ed22 100644 --- a/src/modules/AboutShelter/AboutShelter.jsx +++ b/src/modules/AboutShelter/AboutShelter.jsx @@ -9,12 +9,12 @@ import EditIcon from '../../images/EditIcon/EditIcon'; import DeleteIcon from '../../images/DeleteIcon/DeleteIcon'; import ShelterOwnerStatistics from '../ShelterOwnerStatistics/ShelterOwnerStatistics'; import petLogo from '../../images/pet.jpg'; +import { setPayment } from './api'; // TODO переделать названия классов (объединить?), не совсем понятно, по какому принципу about-shelter, shelter-info const AboutShelter = () => { const { shelter, isOwner, isLoading } = useOutletContext(); - if (isLoading) { return null; } @@ -22,6 +22,15 @@ const AboutShelter = () => { // TODO подключить рероутер на редактирование инфо о приюте (6.2.1.4 в фигме) // TODO сделать попап при удалении приюта (6.2.1.3 в фигме) + const handleSetPayment = async () => { + try { + const paymentConfirmUrl = await setPayment(); + window.open(paymentConfirmUrl, '_blank'); + } catch (error) { + throw new Error(error.message); + } + }; + return (
@@ -100,7 +109,9 @@ const AboutShelter = () => {

Подключить платежную систему

- +
)}
diff --git a/src/modules/AboutShelter/api.js b/src/modules/AboutShelter/api.js new file mode 100644 index 00000000..ec2941c0 --- /dev/null +++ b/src/modules/AboutShelter/api.js @@ -0,0 +1,24 @@ +import { baseUrl, apiHeaders } from '../../utils/constants'; + +// eslint-disable-next-line +export const setPayment = async (id, amount) => { + try { + if (localStorage.getItem('access')) { + const token = localStorage.getItem('access'); + apiHeaders.authorization = `Bearer ${token}`; + } + const response = await fetch(`${baseUrl}/v1/payments/get-partner-link/`, { + method: 'GET', + headers: apiHeaders, + }); + + if (response.ok) { + const data = await response.json(); + delete apiHeaders.authorization; + return data.partner_link; + } + throw new Error('Ошибка при отправке запроса'); + } catch (error) { + throw new Error('Ошибка:', error); + } +}; diff --git a/src/modules/HelpToShelter/ApiHelpToShelter.js b/src/modules/HelpToShelter/ApiHelpToShelter.js index f5e51478..07143ba4 100644 --- a/src/modules/HelpToShelter/ApiHelpToShelter.js +++ b/src/modules/HelpToShelter/ApiHelpToShelter.js @@ -1,13 +1,15 @@ -import { baseUrl } from '../../utils/constants'; +import { baseUrl, apiHeaders } from '../../utils/constants'; // eslint-disable-next-line export const donateToShelter = async (id, amount) => { try { + if (localStorage.getItem('access')) { + const token = localStorage.getItem('access'); + apiHeaders.authorization = `Bearer ${token}`; + } const response = await fetch(`${baseUrl}/v1/payments/shelters/${id}/donate/`, { method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, + headers: apiHeaders, body: JSON.stringify({ amount }) @@ -15,6 +17,7 @@ export const donateToShelter = async (id, amount) => { if (response.ok) { const data = await response.json(); + delete apiHeaders.authorization; return data.payment_confirm_url; } throw new Error('Ошибка при отправке запроса'); diff --git a/src/modules/HelpToShelter/HelpToShelter.jsx b/src/modules/HelpToShelter/HelpToShelter.jsx index 60cd70c0..0fd111d1 100644 --- a/src/modules/HelpToShelter/HelpToShelter.jsx +++ b/src/modules/HelpToShelter/HelpToShelter.jsx @@ -8,14 +8,14 @@ import * as errorMessage from '../../utils/errorMessage'; import useInput from '../../hooks/useInput'; import { donateToShelter } from './ApiHelpToShelter'; + const HelpToShelter = () => { const { id } = useParams(); - const materialAid = useInput('', { notEmpty: true, maxLength: 12, regex: regex.NUMBER }, errorMessage.DONATION_AMOUNT); - const { isOwner, isAuth, isShelterOwner } = useOutletContext(); - + const materialAid = useInput('', { notEmpty: true, maxLength: 12, regex: regex.NUMBER, isZero: true }, errorMessage.DONATION_AMOUNT); + const { shelter } = useOutletContext(); const handleDonate = async () => { - if (materialAid.value !== '') { - const donationAmount = parseInt(materialAid.value, 10); + const donationAmount = parseInt(materialAid.value, 10); + if ((donationAmount > 0) && (materialAid.value.length < 12)) { try { const paymentConfirmUrl = await donateToShelter(id, donationAmount); window.open(paymentConfirmUrl, '_blank'); @@ -27,23 +27,21 @@ const HelpToShelter = () => { return (
- { !isOwner && ( + {shelter.is_partner && (

Материальная помощь

- { (isShelterOwner || isAuth) && (isAuth || isShelterOwner) && ( - - )} + diff --git a/src/modules/ShelterOwnerProfile/ShelterOwnerProfile.jsx b/src/modules/ShelterOwnerProfile/ShelterOwnerProfile.jsx index 672e5168..76849910 100644 --- a/src/modules/ShelterOwnerProfile/ShelterOwnerProfile.jsx +++ b/src/modules/ShelterOwnerProfile/ShelterOwnerProfile.jsx @@ -6,7 +6,6 @@ import ProfileSheltersBlock from '../../components/ProfileSheltersBlock/ProfileS const ShelterOwnerProfile = () => { const currentUser = useContext(CurrentUserContext); const myShelters = [currentUser.own_shelter]; - return (
{ return ( -
  • +
    @@ -20,7 +21,7 @@ const DeclarationInput = ({ caption, inputState, type, name, placeholder, requir required={required} /> {showError &&

    {inputState.dirty && inputState.invalidText}

    } -
  • +
    ); }; diff --git a/src/utils/errorMessage.js b/src/utils/errorMessage.js index 2838adfe..ea8d00a6 100644 --- a/src/utils/errorMessage.js +++ b/src/utils/errorMessage.js @@ -123,4 +123,5 @@ export const VACANCY_DESCRIPTION = { export const DONATION_AMOUNT = { TOO_LONG: tooLong, NOT_FOUND: 'Введите сумму пожертвования', + IS_ZERO: 'Cумма должно превышать нулевое значение', }; \ No newline at end of file