@@ -17,15 +17,25 @@ interface Props {
1717
1818export const PaymentForm : FunctionComponent < Props > = ( { campaign, inlineForm = false , isPayment = false } ) => {
1919 const maxAmount = campaign ? campaign . required_amount : Number . MAX_SAFE_INTEGER ;
20+ const hours_spent = 2 ;
2021 const amount = 100 > maxAmount ? maxAmount : 100 ;
21- const initialState = { amount, email : '' , phone : '' , name : '' } ;
22+ const initialState = { amount, hours_spent , email : '' , phone : '' , name : '' } ;
2223 const [ form , setFormValue ] = useState ( initialState ) ;
2324 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
2425 const [ isModalOpen , toggleModal ] = useState ( false ) ;
2526 const finalAmount = getFinalAmount ( form . amount ) ;
2627 function onChange ( e : ChangeEvent < HTMLInputElement > ) {
2728 e . persist ( ) ;
2829 const value = e . target . value ;
30+ if ( e . target . name === 'hours_spent' ) {
31+ const hours_spent = Number ( value ) ;
32+ const cost = hours_spent > 3 ? hours_spent * 30 : hours_spent * 50 ;
33+ return setFormValue ( form => ( {
34+ ...form ,
35+ [ e . target . name ] : value ,
36+ 'amount' : cost < Number ( maxAmount ) ? cost : maxAmount ,
37+ } ) ) ;
38+ }
2939 if ( e . target . name === 'amount' ) {
3040 return setFormValue ( form => ( {
3141 ...form ,
@@ -35,8 +45,8 @@ export const PaymentForm: FunctionComponent<Props> = ({ campaign, inlineForm = f
3545 setFormValue ( form => ( { ...form , [ e . target . name ] : value } ) ) ;
3646 }
3747
38- function validateForm ( form : { name : string ; email : string ; phone : string ; amount : number } ) {
39- if ( ! form . amount || ! form . email || ! form . phone || ! form . name ) {
48+ function validateForm ( form : { name : string ; email : string ; phone : string ; amount : number , hours_spent : number } ) {
49+ if ( ! form . amount || ! form . email || ! form . phone || ! form . name || ! form . hours_spent ) {
4050 return alert ( `Please enter all required fields` ) ;
4151 }
4252
@@ -55,6 +65,10 @@ export const PaymentForm: FunctionComponent<Props> = ({ campaign, inlineForm = f
5565 return `Enter a valid phone number` ;
5666 }
5767
68+ if ( Number ( form . hours_spent ) < 1 ) {
69+ return alert ( `Hours spent should be greater than or equal to 1` ) ;
70+ }
71+
5872 if ( Number ( form . amount ) < 1 ) {
5973 return alert ( `Amount should be greater than or equal to 1` ) ;
6074 }
@@ -75,6 +89,7 @@ export const PaymentForm: FunctionComponent<Props> = ({ campaign, inlineForm = f
7589 setIsSubmitting ( true ) ;
7690 await openRzp ( {
7791 ...form ,
92+ hours_spent : Number ( form . hours_spent ) ,
7893 amount : Number ( form . amount ) ,
7994 campaign : campaign ? campaign . slug : undefined ,
8095 isPayment
@@ -90,8 +105,27 @@ export const PaymentForm: FunctionComponent<Props> = ({ campaign, inlineForm = f
90105
91106 return (
92107 < div className = { clsx ( ! inlineForm && 'px-4' , inlineForm && 'md:px-0' ) } >
93- < p className = "text-lg mb-4 text-gray-700 leading-relaxed" > We truly appreciate your generosity</ p >
108+ < p className = "text-lg mb-4 text-gray-700 leading-relaxed" > { isPayment ? 'Please make payment for hackerspace here' : ' We truly appreciate your generosity' } </ p >
94109 < form name = "payment" onSubmit = { onSubmit } >
110+ < div className = "mb-4 mt-4" >
111+ < label htmlFor = "amount" className = "text-sm text-gray-800 mb-1 block" >
112+ Hours spent < sup className = "text-red-500" > *</ sup >
113+ </ label >
114+ < div >
115+ < input
116+ className = "bg-white focus:outline-0 border border-gray-300 rounded py-2 px-2 block w-full appearance-none leading-normal"
117+ type = "number"
118+ name = "hours_spent"
119+ id = "hours_spent"
120+ value = { form . hours_spent }
121+ onChange = { onChange }
122+ required
123+ autoFocus = { ! inlineForm }
124+ min = "1"
125+ disabled = { isSubmitting }
126+ />
127+ </ div >
128+ </ div >
95129 < div className = "mb-4 mt-4" >
96130 < label htmlFor = "amount" className = "text-sm text-gray-800 mb-1 block" >
97131 Amount < sup className = "text-red-500" > *</ sup >
@@ -107,7 +141,7 @@ export const PaymentForm: FunctionComponent<Props> = ({ campaign, inlineForm = f
107141 required
108142 autoFocus = { ! inlineForm }
109143 min = "1"
110- disabled = { isSubmitting }
144+ disabled = { isSubmitting || isPayment }
111145 />
112146 </ div >
113147 </ div >
0 commit comments