2018-09-26 19:48:07 +02:00
// @flow
2020-03-13 01:56:02 +01:00
import React , { useState } from 'react' ;
2017-12-21 22:08:54 +01:00
import { Modal } from 'modal/modal' ;
2020-03-13 01:56:02 +01:00
import { FormField } from 'component/common/form' ;
2017-12-21 22:08:54 +01:00
import * as txnTypes from 'constants/transaction_types' ;
2020-05-01 19:55:42 +02:00
import Card from 'component/common/card' ;
import Button from 'component/button' ;
2020-09-02 22:08:37 +02:00
import I18nMessage from 'component/i18nMessage' ;
import LbcSymbol from 'component/common/lbc-symbol' ;
2017-10-27 21:42:54 +02:00
2018-09-26 19:48:07 +02:00
type Props = {
closeModal : ( ) => void ,
2020-04-10 19:31:36 +02:00
abandonTxo : ( Txo , ( ) => void ) => void ,
2022-01-14 20:26:03 +01:00
abandonClaim : ( Claim , ? ( ) => void ) => void ,
2020-04-10 19:31:36 +02:00
tx : Txo ,
2022-01-14 20:26:03 +01:00
claim : Claim ,
2020-04-10 19:31:36 +02:00
cb : ( ) => void ,
2021-06-17 19:57:04 +02:00
doResolveUri : ( string ) => void ,
2018-09-26 19:48:07 +02:00
} ;
2017-10-27 21:42:54 +02:00
2020-03-13 01:56:02 +01:00
export default function ModalRevokeClaim ( props : Props ) {
2021-06-17 19:57:04 +02:00
const { tx , claim , closeModal , abandonTxo , abandonClaim , cb , doResolveUri } = props ;
2020-05-22 03:19:01 +02:00
const { value _type : valueType , type , normalized _name : name , is _my _input : isSupport } = tx || claim ;
2020-03-13 01:56:02 +01:00
const [ channelName , setChannelName ] = useState ( '' ) ;
2017-10-30 17:25:56 +01:00
2021-06-17 19:57:04 +02:00
React . useEffect ( ( ) => {
if ( claim ) {
doResolveUri ( claim . permanent _url ) ;
}
} , [ claim , doResolveUri ] ) ;
2021-06-12 15:46:04 +02:00
const shouldConfirmChannel =
valueType === txnTypes . CHANNEL || type === txnTypes . CHANNEL || ( type === txnTypes . UPDATE && name . startsWith ( '@' ) ) ;
2020-06-07 21:17:18 +02:00
2020-05-22 03:19:01 +02:00
function getButtonLabel ( type : string , isSupport : boolean ) {
if ( isSupport && type === txnTypes . SUPPORT ) {
2021-07-06 15:56:15 +02:00
return _ _ ( 'Confirm Support Removal' ) ;
2020-05-22 03:19:01 +02:00
} else if ( type === txnTypes . SUPPORT ) {
2020-06-20 16:17:11 +02:00
return _ _ ( 'Confirm Tip Unlock' ) ;
2021-07-06 15:56:15 +02:00
} else if ( type === txnTypes . CHANNEL ) {
return _ _ ( 'Confirm Channel Removal' ) ;
2017-11-01 21:23:30 +01:00
}
2021-07-06 15:56:15 +02:00
return _ _ ( 'Confirm Removal' ) ;
2017-11-01 21:23:30 +01:00
}
2020-05-22 03:19:01 +02:00
function getMsgBody ( type : string , isSupport : boolean , name : string ) {
if ( isSupport && type === txnTypes . SUPPORT ) {
2017-11-01 21:23:30 +01:00
return (
2018-09-26 19:48:07 +02:00
< React.Fragment >
2021-07-06 15:56:15 +02:00
< p > { _ _ ( 'Are you sure you want to remove this boost?' ) } < / p >
2017-11-01 21:23:30 +01:00
< p >
2020-09-02 22:08:37 +02:00
< I18nMessage tokens = { { lbc : < LbcSymbol / > } } >
2021-07-07 16:21:17 +02:00
These Credits are permanently yours and this boost can be removed at any time . Removing this boost will
reduce discoverability and return % lbc % to your spendable balance .
2020-09-02 22:08:37 +02:00
< / I18nMessage >
2017-11-01 21:23:30 +01:00
< / p >
2018-09-26 19:48:07 +02:00
< / React.Fragment >
2017-11-01 21:23:30 +01:00
) ;
2019-07-17 05:23:45 +02:00
} else if ( type === txnTypes . SUPPORT ) {
return (
< React.Fragment >
2020-09-04 19:14:48 +02:00
< p > { _ _ ( 'Are you sure you want to unlock these Credits?' ) } < / p >
2019-07-17 05:23:45 +02:00
< p >
{ _ _ (
2021-07-06 15:56:15 +02:00
'These Credits are permanently yours and can be unlocked at any time. Unlocking them allows you to spend them, but reduces discoverability of your content in lookups and search results. It is recommended you leave Credits locked until you need or want to spend them.'
2019-07-17 05:23:45 +02:00
) }
< / p >
< / React.Fragment >
) ;
2020-06-07 21:17:18 +02:00
} else if ( shouldConfirmChannel ) {
2020-03-13 01:56:02 +01:00
return (
< React.Fragment >
< p >
2021-07-07 16:21:17 +02:00
{ _ _ ( 'This will permanently remove your channel. Content published under this channel will be orphaned.' ) }
2020-03-13 01:56:02 +01:00
< / p >
2022-06-06 22:53:36 +02:00
< p >
{ _ _ (
'If this is a YouTube synced channel, it cannot be reprocessed again. Reach out to us via the Help page if you are not sure about deletion.'
) }
< / p >
2021-07-06 15:56:15 +02:00
< p > { _ _ ( 'Are you sure? Type %name% to confirm that you wish to remove the channel.' , { name } ) } < / p >
2021-07-07 16:21:17 +02:00
< FormField type = { 'text' } onChange = { ( e ) => setChannelName ( e . target . value ) } / >
2020-03-13 01:56:02 +01:00
< / React.Fragment >
) ;
2017-12-21 22:08:54 +01:00
}
2020-03-13 01:56:02 +01:00
2017-12-21 22:08:54 +01:00
return (
2018-09-26 19:48:07 +02:00
< React.Fragment >
2021-07-06 15:56:15 +02:00
< p > { _ _ ( 'Are you sure you want to remove this?' ) } < / p >
2017-12-21 22:08:54 +01:00
< p >
2020-09-02 22:08:37 +02:00
< I18nMessage tokens = { { lbc : < LbcSymbol / > } } >
This will prevent others from resolving and accessing the content you published . It will return the % lbc % to
2021-07-06 15:56:15 +02:00
your spendable balance .
2020-09-02 22:08:37 +02:00
< / I18nMessage >
2017-12-21 22:08:54 +01:00
< / p >
2020-04-13 21:16:07 +02:00
< p className = "help error__text" > { _ _ ( 'FINAL WARNING: This action is permanent and cannot be undone.' ) } < / p >
2018-09-26 19:48:07 +02:00
< / React.Fragment >
2017-12-21 22:08:54 +01:00
) ;
2017-10-27 21:42:54 +02:00
}
2020-03-13 01:56:02 +01:00
function revokeClaim ( ) {
2022-01-14 20:26:03 +01:00
tx ? abandonTxo ( tx , cb ) : abandonClaim ( claim , cb ) ;
2020-04-10 19:31:36 +02:00
closeModal ( ) ;
2018-09-26 19:48:07 +02:00
}
2020-05-22 03:19:01 +02:00
const label = getButtonLabel ( type , isSupport ) ;
2020-05-01 19:55:42 +02:00
2020-03-13 01:56:02 +01:00
return (
2020-06-07 21:17:18 +02:00
< Modal isOpen contentLabel = { label } type = "card" onAborted = { closeModal } >
2020-05-01 19:55:42 +02:00
< Card
title = { label }
2020-05-22 03:19:01 +02:00
body = { getMsgBody ( type , isSupport , name ) }
2020-05-01 19:55:42 +02:00
actions = {
< div className = "section__actions" >
2020-06-07 21:17:18 +02:00
< Button
disabled = { shouldConfirmChannel && name !== channelName }
button = "primary"
label = { label }
onClick = { revokeClaim }
/ >
2020-05-01 19:55:42 +02:00
< Button button = "link" label = { _ _ ( 'Cancel' ) } onClick = { closeModal } / >
< / div >
}
/ >
2020-03-13 01:56:02 +01:00
< / Modal >
) ;
2017-10-27 21:42:54 +02:00
}