import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import './light.css';
import { Container, Form, Grid, Header, Input } from 'semantic-ui-react';
import { PayPalPayNow, PayPalSubscribe } from './PayPal.js';
import { MembersDropdown } from './Members.js';
import { requester } from './utils.js';
export function PayWithProtocoin(props) {
const { token, user, refreshUser, amount, onSuccess, custom } = props;
const member = user.member;
const [error, setError] = useState({});
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const handleSubmit = (e) => {
if (loading) return;
setSuccess(false);
setLoading(true);
const data = { amount: amount, ...custom, balance: member.protocoin };
requester('/protocoin/spend_request/', 'POST', token, data)
.then(res => {
setLoading(false);
setSuccess(true);
if (onSuccess) {
onSuccess();
}
setError({});
refreshUser();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
return (
Pay with Protocoin
{success && Success!
}
);
};
export function SendProtocoin(props) {
const { token, user, refreshUser } = props;
const member = user.member;
const [input, setInput] = useState({});
const [error, setError] = useState({});
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value });
const handleChange = (e) => handleValues(e, e.currentTarget);
const handleSubmit = (e) => {
if (loading) return;
setSuccess(false);
setLoading(true);
const data = { ...input, balance: member.protocoin };
requester('/protocoin/send_to_member/', 'POST', token, data)
.then(res => {
setLoading(false);
setSuccess(true);
setInput({});
setError({});
refreshUser();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
return (
Send
{success && Success!
}
);
};
export function Paymaster(props) {
const { token, user, refreshUser } = props;
const [locker, setLocker] = useState('5.00');
const [consumables, setConsumables] = useState('');
const [buyProtocoin, setBuyProtocoin] = useState('10.00');
const [consumablesMemo, setConsumablesMemo] = useState('');
const [donate, setDonate] = useState('');
const [memo, setMemo] = useState('');
const monthly_fees = user.member.monthly_fees || 55;
return (
Use these buttons to send money to Protospace.
Protocoin is used to buy things from Protospace's vending machines. No cash value.
Current balance: ₱ {user.member.protocoin.toFixed(2)}
Total circulation: ₱ {user.member.total_protocoin.toFixed(2)}
Buy any amount of Protocoin:
setBuyProtocoin(v.value)}
/>
See a director to purchase Protocoin with a different payment method.
Send Protocoin:
Pay ${monthly_fees}.00 once:
Subscribe ${monthly_fees}.00 / month:
Pay ${monthly_fees * 11}.00 for a year:
...get one month for free!
Pay for materials you use (ie. welding gas, 3D printing, etc).
Custom amount:
setConsumables(v.value)}
/>
Please explain what you bought:
setConsumablesMemo(v.value)}
/>
setConsumables('')}
custom={{ category: 'Consumables', memo: consumablesMemo }}
/>
Donation of any amount to Protospace.
Custom amount:
setDonate(v.value)}
/>
Optional memo:
setMemo(v.value)}
/>
setDonate('')}
custom={{ category: 'Donation', memo: memo }}
/>
Confirm location and availability with Scott Young before subscribing.
Custom amount:
setLocker(v.value)}
/>
);
};