lbry-desktop/ui/component/claimSupportButton/view.jsx

64 lines
1.9 KiB
React
Raw Normal View History

2020-02-12 19:59:48 +01:00
// @flow
import * as MODALS from 'constants/modal_types';
import * as ICONS from 'constants/icons';
import React from 'react';
2020-09-30 20:46:17 +02:00
import classnames from 'classnames';
2020-02-12 19:59:48 +01:00
import Button from 'component/button';
2020-11-10 06:21:04 +01:00
import usePersistedState from 'effects/use-persisted-state';
2020-02-12 19:59:48 +01:00
type Props = {
uri: string,
doOpenModal: (string, {}) => void,
2020-09-30 20:46:17 +02:00
fileAction?: boolean,
disableSupport: boolean,
2020-11-10 06:21:04 +01:00
user: ?User,
2020-02-12 19:59:48 +01:00
};
export default function ClaimSupportButton(props: Props) {
2020-11-10 06:21:04 +01:00
const { doOpenModal, uri, fileAction, disableSupport, user } = props;
const [showNudge, setShowNudge] = React.useState(false);
const [nudgeAcknowledged, setNudgeAcknowledged] = usePersistedState('nudge:support-acknowledge', false);
const emailVerified = user && user.has_verified_email;
React.useEffect(() => {
if (!emailVerified && !nudgeAcknowledged && fileAction) {
setShowNudge(true);
}
}, [emailVerified, nudgeAcknowledged, fileAction]);
if (disableSupport) {
return null;
}
2020-11-10 06:21:04 +01:00
2020-02-12 19:59:48 +01:00
return (
2020-11-10 06:21:04 +01:00
<>
<Button
button={fileAction ? undefined : 'alt'}
className={classnames({ 'button--file-action': fileAction, 'button--highlighted': showNudge })}
icon={ICONS.LBC}
iconSize={fileAction ? 22 : undefined}
label={__('Support --[button to support a claim]--')}
requiresAuth={IS_WEB}
title={__('Support this claim')}
onClick={() => doOpenModal(MODALS.SEND_TIP, { uri, isSupport: true })}
/>
{showNudge && (
<div className="nudge">
<div className="nudge__wrapper">
<span className="nudge__text">{__('Create an account to support this creator!')}</span>
<Button
className="nudge__close"
button="close"
icon={ICONS.REMOVE}
onClick={() => {
setNudgeAcknowledged(true);
setShowNudge(false);
}}
/>
</div>
</div>
)}
</>
2020-02-12 19:59:48 +01:00
);
}