disable review button if no card saved also some cleanup #6535
3 changed files with 21 additions and 20 deletions
|
@ -84,16 +84,14 @@ export function CommentCreate(props: Props) {
|
||||||
const [commentValue, setCommentValue] = React.useState('');
|
const [commentValue, setCommentValue] = React.useState('');
|
||||||
const [advancedEditor, setAdvancedEditor] = usePersistedState('comment-editor-mode', false);
|
const [advancedEditor, setAdvancedEditor] = usePersistedState('comment-editor-mode', false);
|
||||||
const hasChannels = channels && channels.length;
|
const hasChannels = channels && channels.length;
|
||||||
const disabled = isSubmitting || !activeChannelClaim || !commentValue.length;
|
|
||||||
const charCount = commentValue.length;
|
const charCount = commentValue.length;
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = React.useState('');
|
const [activeTab, setActiveTab] = React.useState('');
|
||||||
|
|
||||||
const [tipError, setTipError] = React.useState();
|
const [tipError, setTipError] = React.useState();
|
||||||
|
|
||||||
// React.useEffect(() => {
|
const disabled = isSubmitting || !activeChannelClaim || !commentValue.length;
|
||||||
// setTipError('yes');
|
const [shouldDisableReviewButton, setShouldDisableReviewButton] = React.useState();
|
||||||
// }, []);
|
|
||||||
|
|
||||||
function handleCommentChange(event) {
|
function handleCommentChange(event) {
|
||||||
let commentValue;
|
let commentValue;
|
||||||
|
@ -373,10 +371,10 @@ export function CommentCreate(props: Props) {
|
||||||
autoFocus={isReply}
|
autoFocus={isReply}
|
||||||
textAreaMaxLength={livestream ? FF_MAX_CHARS_IN_LIVESTREAM_COMMENT : FF_MAX_CHARS_IN_COMMENT}
|
textAreaMaxLength={livestream ? FF_MAX_CHARS_IN_LIVESTREAM_COMMENT : FF_MAX_CHARS_IN_COMMENT}
|
||||||
/>
|
/>
|
||||||
{/* TODO: the tip validation is done in selector */}
|
|
||||||
{isSupportComment && (
|
{isSupportComment && (
|
||||||
<WalletTipAmountSelector
|
<WalletTipAmountSelector
|
||||||
onTipErrorChange={setTipError}
|
onTipErrorChange={setTipError}
|
||||||
|
shouldDisableReviewButton={setShouldDisableReviewButton}
|
||||||
claim={claim}
|
claim={claim}
|
||||||
activeTab={activeTab}
|
activeTab={activeTab}
|
||||||
amount={tipAmount}
|
amount={tipAmount}
|
||||||
|
@ -387,8 +385,7 @@ export function CommentCreate(props: Props) {
|
||||||
{isSupportComment ? (
|
{isSupportComment ? (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
// TODO: add better check here
|
disabled={disabled || tipError || shouldDisableReviewButton}
|
||||||
disabled={disabled || tipError}
|
|
||||||
type="button"
|
type="button"
|
||||||
button="primary"
|
button="primary"
|
||||||
icon={activeTab === TAB_LBC ? ICONS.LBC : ICONS.FINANCE}
|
icon={activeTab === TAB_LBC ? ICONS.LBC : ICONS.FINANCE}
|
||||||
|
|
|
@ -476,8 +476,8 @@ function WalletSendTip(props: Props) {
|
||||||
|
|
||||||
{activeTab === TAB_FIAT && !hasCardSaved && (
|
{activeTab === TAB_FIAT && !hasCardSaved && (
|
||||||
<h3 className="add-card-prompt">
|
<h3 className="add-card-prompt">
|
||||||
<Button navigate={`/$/${PAGES.SETTINGS_STRIPE_CARD}`} label={__('Add a Card')} button="link" /> To
|
<Button navigates={`/$/${PAGES.SETTINGS_STRIPE_CARD}`} label={__('Add a Card')} button="link" />
|
||||||
{__('Tip Creators')}
|
{' '}{__('To Tip Creators')}
|
||||||
</h3>
|
</h3>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
@ -34,25 +34,32 @@ type Props = {
|
||||||
uri: string,
|
uri: string,
|
||||||
onTipErrorChange: (string) => void,
|
onTipErrorChange: (string) => void,
|
||||||
activeTab: string,
|
activeTab: string,
|
||||||
|
shouldDisableReviewButton: (boolean) => void
|
||||||
};
|
};
|
||||||
|
|
||||||
function WalletTipAmountSelector(props: Props) {
|
function WalletTipAmountSelector(props: Props) {
|
||||||
const { balance, amount, onChange, activeTab, claim, onTipErrorChange } = props;
|
const { balance, amount, onChange, activeTab, claim, onTipErrorChange, shouldDisableReviewButton } = props;
|
||||||
const [useCustomTip, setUseCustomTip] = usePersistedState('comment-support:useCustomTip', false);
|
const [useCustomTip, setUseCustomTip] = usePersistedState('comment-support:useCustomTip', false);
|
||||||
const [tipError, setTipError] = React.useState();
|
const [tipError, setTipError] = React.useState();
|
||||||
|
|
||||||
const [canReceiveFiatTip, setCanReceiveFiatTip] = React.useState(); // dont persist because it needs to be calc'd per creator
|
const [canReceiveFiatTip, setCanReceiveFiatTip] = React.useState(); // dont persist because it needs to be calc'd per creator
|
||||||
const [hasCardSaved, setHasSavedCard] = usePersistedState('comment-support:hasCardSaved', false);
|
const [hasCardSaved, setHasSavedCard] = usePersistedState('comment-support:hasCardSaved', false);
|
||||||
|
|
||||||
|
// if it's fiat but there's no card saved OR the creator can't receive fiat tips
|
||||||
|
const shouldDisableFiatSelectors = (activeTab === TAB_FIAT && (!hasCardSaved || !canReceiveFiatTip));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* whether tip amount selection/review functionality should be disabled
|
||||||
|
* @param [amount] LBC amount (optional)
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
function shouldDisableAmountSelector(amount) {
|
function shouldDisableAmountSelector(amount) {
|
||||||
return (
|
// if it's LBC but the balance isn't enough, or fiat conditions met
|
||||||
(amount > balance && activeTab !== TAB_FIAT) || (activeTab === TAB_FIAT && (!hasCardSaved || !canReceiveFiatTip))
|
// $FlowFixMe
|
||||||
);
|
return (amount > balance && activeTab !== TAB_FIAT) || shouldDisableFiatSelectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(activeTab);
|
shouldDisableReviewButton(shouldDisableFiatSelectors);
|
||||||
|
|
||||||
console.log(claim);
|
|
||||||
|
|
||||||
|
|||||||
// setup variables for tip API
|
// setup variables for tip API
|
||||||
let channelClaimId, tipChannelName;
|
let channelClaimId, tipChannelName;
|
||||||
|
@ -83,9 +90,6 @@ function WalletTipAmountSelector(props: Props) {
|
||||||
customerStatusResponse.Customer.invoice_settings.default_payment_method &&
|
customerStatusResponse.Customer.invoice_settings.default_payment_method &&
|
||||||
customerStatusResponse.Customer.invoice_settings.default_payment_method.id;
|
customerStatusResponse.Customer.invoice_settings.default_payment_method.id;
|
||||||
|
|
||||||
console.log('here');
|
|
||||||
console.log(defaultPaymentMethodId);
|
|
||||||
|
|
||||||
setHasSavedCard(Boolean(defaultPaymentMethodId));
|
setHasSavedCard(Boolean(defaultPaymentMethodId));
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -230,6 +234,7 @@ function WalletTipAmountSelector(props: Props) {
|
||||||
<FormField
|
<FormField
|
||||||
autoFocus
|
autoFocus
|
||||||
name="tip-input"
|
name="tip-input"
|
||||||
|
disabled={shouldDisableAmountSelector()}
|
||||||
label={
|
label={
|
||||||
activeTab === TAB_LBC ? (
|
activeTab === TAB_LBC ? (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -239,7 +244,6 @@ function WalletTipAmountSelector(props: Props) {
|
||||||
</I18nMessage>
|
</I18nMessage>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
) : (
|
) : (
|
||||||
// TODO: add conditional based on hasSavedCard
|
|
||||||
<></>
|
<></>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue
if you supply an inititial value to useState(false), flow wouldn't complain here.