2022-08-05 11:13:27 +00:00
|
|
|
import { Conditional } from 'components/Conditional'
|
2022-08-04 09:16:42 +00:00
|
|
|
import { FormGroup } from 'components/FormGroup'
|
2022-09-01 06:27:23 +00:00
|
|
|
import { useInputState } from 'components/forms/FormInput.hooks'
|
2022-08-05 11:13:27 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2022-08-04 09:16:42 +00:00
|
|
|
|
|
|
|
import { NumberInput, TextInput } from '../../forms/FormInput'
|
|
|
|
|
|
|
|
interface RoyaltyDetailsProps {
|
|
|
|
onChange: (data: RoyaltyDetailsDataProps) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RoyaltyDetailsDataProps {
|
2022-08-05 11:13:27 +00:00
|
|
|
royaltyType: RoyaltyState
|
2022-08-04 09:16:42 +00:00
|
|
|
paymentAddress: string
|
|
|
|
share: number
|
|
|
|
}
|
|
|
|
|
2022-08-05 11:13:27 +00:00
|
|
|
type RoyaltyState = 'none' | 'new'
|
|
|
|
|
2022-08-04 09:16:42 +00:00
|
|
|
export const RoyaltyDetails = ({ onChange }: RoyaltyDetailsProps) => {
|
2022-08-05 11:13:27 +00:00
|
|
|
const [royaltyState, setRoyaltyState] = useState<RoyaltyState>('none')
|
|
|
|
|
2022-08-04 09:16:42 +00:00
|
|
|
const royaltyPaymentAddressState = useInputState({
|
|
|
|
id: 'royalty-payment-address',
|
|
|
|
name: 'royaltyPaymentAddress',
|
|
|
|
title: 'Payment Address',
|
|
|
|
subtitle: 'Address to receive royalties',
|
|
|
|
placeholder: 'stars1234567890abcdefghijklmnopqrstuvwxyz...',
|
|
|
|
})
|
|
|
|
|
2022-09-01 06:27:23 +00:00
|
|
|
const royaltyShareState = useInputState({
|
2022-08-04 09:16:42 +00:00
|
|
|
id: 'royalty-share',
|
|
|
|
name: 'royaltyShare',
|
|
|
|
title: 'Share Percentage',
|
|
|
|
subtitle: 'Percentage of royalties to be paid',
|
2022-09-01 06:27:23 +00:00
|
|
|
placeholder: '8%',
|
2022-08-04 09:16:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const data: RoyaltyDetailsDataProps = {
|
2022-08-05 11:13:27 +00:00
|
|
|
royaltyType: royaltyState,
|
2022-08-04 09:16:42 +00:00
|
|
|
paymentAddress: royaltyPaymentAddressState.value,
|
2022-09-01 06:27:23 +00:00
|
|
|
share: Number(royaltyShareState.value),
|
2022-08-04 09:16:42 +00:00
|
|
|
}
|
|
|
|
onChange(data)
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2022-08-09 11:42:55 +00:00
|
|
|
}, [royaltyState, royaltyPaymentAddressState.value, royaltyShareState.value])
|
2022-08-04 09:16:42 +00:00
|
|
|
|
|
|
|
return (
|
2022-08-05 11:13:27 +00:00
|
|
|
<div className="py-3 px-8 rounded border-2 border-white/20">
|
|
|
|
<div className="flex justify-center">
|
|
|
|
<div className="ml-4 font-bold form-check form-check-inline">
|
|
|
|
<input
|
|
|
|
checked={royaltyState === 'none'}
|
|
|
|
className="float-none mr-2 mb-1 w-4 h-4 align-middle bg-white checked:bg-stargaze bg-center bg-no-repeat bg-contain rounded-full border border-gray-300 checked:border-white focus:outline-none transition duration-200 appearance-none cursor-pointer form-check-input"
|
|
|
|
id="royaltyRadio1"
|
|
|
|
name="royaltyRadioOptions1"
|
|
|
|
onClick={() => {
|
|
|
|
setRoyaltyState('none')
|
|
|
|
}}
|
|
|
|
type="radio"
|
|
|
|
value="None"
|
|
|
|
/>
|
|
|
|
<label className="inline-block text-white cursor-pointer form-check-label" htmlFor="royaltyRadio1">
|
|
|
|
No royalty
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div className="ml-4 font-bold form-check form-check-inline">
|
|
|
|
<input
|
|
|
|
checked={royaltyState === 'new'}
|
|
|
|
className="float-none mr-2 mb-1 w-4 h-4 align-middle bg-white checked:bg-stargaze bg-center bg-no-repeat bg-contain rounded-full border border-gray-300 checked:border-white focus:outline-none transition duration-200 appearance-none cursor-pointer form-check-input"
|
|
|
|
id="royaltyRadio2"
|
|
|
|
name="royaltyRadioOptions2"
|
|
|
|
onClick={() => {
|
|
|
|
setRoyaltyState('new')
|
|
|
|
}}
|
|
|
|
type="radio"
|
|
|
|
value="Existing"
|
|
|
|
/>
|
|
|
|
<label className="inline-block text-white cursor-pointer form-check-label" htmlFor="royaltyRadio2">
|
2022-08-09 11:42:55 +00:00
|
|
|
Configure royalty details
|
2022-08-05 11:13:27 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Conditional test={royaltyState === 'new'}>
|
|
|
|
<FormGroup subtitle="Information about royalty" title="Royalty Details">
|
2022-09-01 06:27:23 +00:00
|
|
|
<TextInput {...royaltyPaymentAddressState} isRequired />
|
|
|
|
<NumberInput {...royaltyShareState} isRequired />
|
2022-08-05 11:13:27 +00:00
|
|
|
</FormGroup>
|
|
|
|
</Conditional>
|
2022-08-04 09:16:42 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|