2015-02-19 07:17:31 +01:00
var React = require ( 'react' ) ,
CartStore = require ( '../../stores/cartStore' ) ,
AddToCart = require ( '../cart/addToCart' ) ,
CartActions = require ( '../../actions/cartActions' ) ,
NavigationActions = require ( '../../actions/navigationActions' ) ,
SingleItem = require ( '../items/singleItem' ) ,
Globals = require ( '../../globals' ) ,
2016-01-06 08:26:19 +01:00
CartTotal = require ( './cartTotal' ) ,
2015-03-29 12:46:51 +02:00
LinkBanner = require ( '../linkBanner/linkBanner' ) ,
2015-11-14 04:39:05 +01:00
PaymentSelect = require ( '../payment/paymentSelect' ) ,
2016-01-08 10:21:33 +01:00
RibicaFormError = require ( '../shared/ribicaFormError' ) ,
2016-01-11 10:21:11 +01:00
PaypalButton = require ( '../payment/paypalButton' ) ,
2016-01-11 10:52:18 +01:00
PikpayButton = require ( '../payment/pikpayButton' ) ,
2016-01-11 10:21:11 +01:00
CashOnDeliveryButton = require ( '../payment/cashOnDeliveryButton' ) ;
2015-02-19 07:17:31 +01:00
var Router = require ( 'react-router' ) ;
var CheckoutPage = React . createClass ( {
render : function ( ) {
2016-01-06 08:26:19 +01:00
var choosePayment = (
< div className = "payment-btn" >
2016-01-11 08:53:03 +01:00
< PaymentSelect deliveryDestination = { this . state . deliveryDestination }
amount = { CartStore . getAmount ( ) }
deliveryCost = { CartStore . getDeliveryCost ( false ) }
disabled = { ! this . state . isDeliveryDestinationValid }
2016-01-12 15:18:27 +01:00
cashOnDeliveryDisabled = { ! this . state . isDeliveryDestinationValid || this . state . deliveryDestination . get ( 'gift' ) }
2016-01-11 08:53:03 +01:00
onCashClick = { this . _onOrderClick }
2016-01-13 09:26:28 +01:00
cartId = { this . state . cart . get ( 'id' ) }
2016-01-11 08:53:03 +01:00
/ >
2015-11-14 04:39:05 +01:00
< / d i v >
) ;
2016-01-08 10:21:33 +01:00
var last _used _payment ;
2016-01-11 10:21:11 +01:00
if ( this . state . deliveryDestination . get ( 'payment_method' ) == 'paypal' ) {
2016-01-08 10:21:33 +01:00
last _used _payment = (
2016-01-13 09:26:28 +01:00
< PaypalButton disabled = { ! this . state . isDeliveryDestinationValid } onSubmitPaypal = { this . _handleOnSubmitPaypal } deliveryDestination = { this . state . deliveryDestination } amount = { CartStore . getAmount ( ) } deliveryCost = { CartStore . getDeliveryCost ( false ) } cartId = { this . state . cart . get ( 'id' ) } / >
2016-01-08 10:21:33 +01:00
) ;
} else if ( this . state . deliveryDestination . get ( 'payment_method' ) == 'pikpay' ) {
2016-01-13 09:26:28 +01:00
last _used _payment = (
< PikpayButton amount = { CartStore . getAmount ( ) } deliveryCost = { CartStore . getDeliveryCost ( false ) } disabled = { ! this . state . isDeliveryDestinationValid } deliveryDestination = { this . state . deliveryDestination } cartId = { this . state . cart . get ( 'id' ) } / >
) ;
2016-01-08 10:21:33 +01:00
} else {
last _used _payment = (
2016-01-13 09:26:28 +01:00
< CashOnDeliveryButton onCashClick = { this . _onOrderClick } disabled = { ! this . state . isDeliveryDestinationValid || this . state . deliveryDestination . get ( 'gift' ) } cartId = { this . state . cart . get ( 'id' ) } / >
2016-01-08 10:21:33 +01:00
) ;
}
2016-01-07 15:00:59 +01:00
2015-06-14 06:18:10 +02:00
var supportedPlaceOptions = CartStore . getSupportedPlaces ( ) . map ( function ( p ) { return ( < option value = { p . code } > { p . placeLabel } < / o p t i o n > ) } ) ;
2016-01-06 08:26:19 +01:00
2015-06-14 06:18:10 +02:00
var content = (
2015-02-23 07:08:23 +01:00
< div className = "checkout-page center" >
2015-07-05 13:44:38 +02:00
< div className = "form-horizontal checkout_form_margin" >
2015-02-26 06:48:34 +01:00
< fieldset >
2016-01-11 16:03:53 +01:00
< legend > Podaci o naručiocu < / l e g e n d >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-03-11 07:32:05 +01:00
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "name" > Prezime i Ime < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< RibicaFormError componentName = "name" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
2015-02-26 06:48:34 +01:00
< input id = "name" name = "name" type = "text" placeholder = "Prezime Ime" className = "form-control input-md" required = "" value = { this . state . deliveryDestination . get ( 'name' ) } onChange = { this . _onFieldChange } / >
< span className = "help-block" > ime osobe koja prima pošiljku < / s p a n >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "name" > Adresa < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< RibicaFormError componentName = "address" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
2015-02-26 06:48:34 +01:00
< input id = "address" name = "address" type = "text" placeholder = "Ulica i broj" className = "form-control input-md" required = "" value = { this . state . deliveryDestination . get ( 'address' ) } onChange = { this . _onFieldChange } / >
< span className = "help-block" > adresa na koju će roba biti isporučena < / s p a n >
< / d i v >
< / d i v >
2016-01-06 08:26:19 +01:00
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "place" > Mjesto < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< RibicaFormError componentName = "place" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
2015-02-26 06:48:34 +01:00
< select id = "place" name = "place" className = "form-control" value = { this . state . deliveryDestination . get ( 'place' ) } onChange = { this . _onFieldChange } >
2016-01-06 08:26:19 +01:00
{ supportedPlaceOptions }
2015-02-26 06:48:34 +01:00
< / s e l e c t >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "phone" > Telefon < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< RibicaFormError componentName = "phone" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
2015-02-26 06:48:34 +01:00
< div className = "input-group" >
2015-05-11 11:35:24 +02:00
< span className = "input-group-addon" > + 387 < / s p a n >
< input id = "phone" name = "phone" className = "form-control" placeholder = "061 222 333" type = "text" required = "" value = { this . state . deliveryDestination . get ( 'phone' ) } onChange = { this . _onFieldChange } / >
2015-02-26 06:48:34 +01:00
< / d i v >
< p className = "help-block" > broj mobitela - mora biti sa jedne od mreža u BiH < / p >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "email" > E - mail < / l a b e l >
< div className = "col-md-4" >
2015-03-11 07:32:05 +01:00
< RibicaFormError componentName = "email" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
2015-02-26 06:48:34 +01:00
< input id = "email" name = "email" type = "text" placeholder = "ime@nekimail.com" className = "form-control input-md" required = "" value = { this . state . deliveryDestination . get ( 'email' ) } onChange = { this . _onFieldChange } / >
< span className = "help-block" > E - mail adresa na koju će vam biti poslano obavještenje o narudžbi < / s p a n >
< / d i v >
< / d i v >
2015-07-05 13:44:38 +02:00
< div className = "form-group " >
2015-02-26 06:48:34 +01:00
< label className = "col-md-4 control-label" htmlFor = "note" > Napomena < / l a b e l >
< div className = "col-md-4" >
< textarea className = "form-control" id = "note" name = "note" value = { this . state . deliveryDestination . get ( 'note' ) } onChange = { this . _onFieldChange } > < / t e x t a r e a >
< / d i v >
< / d i v >
2016-01-11 08:53:03 +01:00
< div className = "form-group" >
< label className = "col-md-4 control-label" htmlFor = "order" > < / l a b e l >
< div className = "col-md-8" >
< div > Roba : < CartTotal items = { this . state . items } itemCounts = { this . state . itemCounts } / > < br / >
2016-01-12 15:18:27 +01:00
< span className = { this . state . deliveryDestinationErrors [ this . state . deliveryCostsTarget ] ? 'hidden' : 'shown' } >
2016-01-11 08:53:03 +01:00
Dostava : < CartTotal deliveryCosts = { this . state . deliveryCosts } / > < br / >
Ukupno : < CartTotal items = { this . state . items } itemCounts = { this . state . itemCounts } deliveryCosts = { this . state . deliveryCosts } / >
2015-11-07 07:41:08 +01:00
< / s p a n >
2016-01-11 08:53:03 +01:00
< / d i v >
2016-01-11 16:03:53 +01:00
< br / >
< div className = "checkbox" >
2016-01-12 09:01:46 +01:00
< label > < input type = "checkbox" name = "gift" checked = { this . state . deliveryDestination . get ( 'gift' ) } onChange = { this . _onFieldChange } / > Poklon < / l a b e l >
2016-01-11 16:03:53 +01:00
< / d i v >
2015-02-26 06:48:34 +01:00
< / d i v >
2016-01-11 08:53:03 +01:00
< / d i v >
2015-11-14 04:39:05 +01:00
2016-01-11 16:03:53 +01:00
2016-01-06 08:26:19 +01:00
< / f i e l d s e t >
2015-11-14 04:39:05 +01:00
2016-01-11 16:03:53 +01:00
< fieldset className = { this . state . deliveryDestination . get ( 'gift' ) ? 'shown' : 'hidden' } >
< legend > Podaci o dostavi < / l e g e n d >
2016-01-12 09:01:46 +01:00
2016-01-11 16:03:53 +01:00
< div className = "form-group " >
2015-11-14 04:39:05 +01:00
2016-01-12 13:26:43 +01:00
< label className = "col-md-4 control-label" htmlFor = "recipient_name" > Prezime i Ime < / l a b e l >
2016-01-11 16:03:53 +01:00
< div className = "col-md-4" >
2016-01-12 13:26:43 +01:00
< RibicaFormError componentName = "recipient_name" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
< input id = "recipient_name" name = "recipient_name" type = "text" placeholder = "Prezime Ime" className = "form-control input-md" required = "" value = { this . state . deliveryDestination . get ( 'recipient_name' ) } onChange = { this . _onFieldChange } / >
2016-01-11 16:03:53 +01:00
< span className = "help-block" > ime osobe koja prima pošiljku < / s p a n >
< / d i v >
< / d i v >
< div className = "form-group " >
2016-01-12 13:26:43 +01:00
< label className = "col-md-4 control-label" htmlFor = "recipient_address" > Adresa < / l a b e l >
2016-01-11 16:03:53 +01:00
< div className = "col-md-4" >
2016-01-12 13:26:43 +01:00
< RibicaFormError componentName = "recipient_address" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
< input id = "recipient_address" name = "recipient_address" type = "text" placeholder = "Ulica i broj" className = "form-control input-md" required = "" value = { this . state . deliveryDestination . get ( 'recipient_address' ) } onChange = { this . _onFieldChange } / >
2016-01-11 16:03:53 +01:00
< span className = "help-block" > adresa na koju će roba biti isporučena < / s p a n >
< / d i v >
< / d i v >
2016-01-12 09:01:46 +01:00
< div className = "form-group " >
2016-01-12 13:26:43 +01:00
< label className = "col-md-4 control-label" htmlFor = "recipient_place" > Mjesto < / l a b e l >
2016-01-12 09:01:46 +01:00
< div className = "col-md-4" >
2016-01-12 13:26:43 +01:00
< RibicaFormError componentName = "recipient_place" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
< select id = "recipient_place" name = "recipient_place" className = "form-control" value = { this . state . deliveryDestination . get ( 'recipient_place' ) } onChange = { this . _onFieldChange } >
2016-01-11 16:03:53 +01:00
2016-01-12 09:01:46 +01:00
{ supportedPlaceOptions }
2016-01-11 16:03:53 +01:00
2016-01-12 09:01:46 +01:00
< / s e l e c t >
2016-01-11 16:03:53 +01:00
< / d i v >
2016-01-12 09:01:46 +01:00
< / d i v >
< div className = "form-group " >
2016-01-12 13:26:43 +01:00
< label className = "col-md-4 control-label" htmlFor = "recipient_phone" > Telefon < / l a b e l >
2016-01-12 09:01:46 +01:00
< div className = "col-md-4" >
2016-01-12 13:26:43 +01:00
< RibicaFormError componentName = "recipient_phone" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
2016-01-12 09:01:46 +01:00
< div className = "input-group" >
< span className = "input-group-addon" > + 387 < / s p a n >
2016-01-12 13:26:43 +01:00
< input id = "recipient_phone" name = "recipient_phone" className = "form-control" placeholder = "061 222 333" type = "text" required = "" value = { this . state . deliveryDestination . get ( 'recipient_phone' ) } onChange = { this . _onFieldChange } / >
2016-01-11 16:03:53 +01:00
< / d i v >
2016-01-12 09:01:46 +01:00
< p className = "help-block" > broj mobitela - mora biti sa jedne od mreža u BiH < / p >
2016-01-11 16:03:53 +01:00
< / d i v >
2016-01-12 09:01:46 +01:00
< / d i v >
< div className = "form-group " >
2016-01-12 13:26:43 +01:00
< label className = "col-md-4 control-label" htmlFor = "recipient_email" > E - mail < / l a b e l >
2016-01-12 09:01:46 +01:00
< div className = "col-md-4" >
2016-01-12 13:26:43 +01:00
< RibicaFormError componentName = "recipient_email" errorMessagesObject = { this . state . deliveryDestinationErrors } / >
< input id = "recipient_email" name = "recipient_email" type = "text" placeholder = "ime@nekimail.com" className = "form-control input-md" required = "" value = { this . state . deliveryDestination . get ( 'recipient_email' ) } onChange = { this . _onFieldChange } / >
2016-01-12 09:01:46 +01:00
< span className = "help-block" > E - mail adresa na koju će vam biti poslano obavještenje o narudžbi < / s p a n >
2016-01-11 16:03:53 +01:00
< / d i v >
2016-01-12 09:01:46 +01:00
< / d i v >
2016-01-11 16:03:53 +01:00
< / f i e l d s e t >
< div className = "payment-select-container" >
{ choosePayment }
< / d i v >
< / d i v >
< / d i v >
2016-01-06 08:26:19 +01:00
) ;
2015-06-14 06:18:10 +02:00
if ( CartStore . isAddressColapsed ( ) ) {
var address = CartStore . getHumanReadableAddress ( ) . map ( function ( a ) { return ( < span > { a } < br / > < / s p a n > ) } ) ;
content = (
< div className = "checkout-page center text-center" >
< h2 > Roba će biti dostavljena na adresu : < / h 2 >
< p className = "lead" >
{ address }
< br / >
2015-07-05 13:22:47 +02:00
Roba : < CartTotal items = { this . state . items } itemCounts = { this . state . itemCounts } / > < br / >
Dostava : < CartTotal deliveryCosts = { this . state . deliveryCosts } / > < br / >
2015-06-14 06:18:10 +02:00
Ukupno : < CartTotal items = { this . state . items } itemCounts = { this . state . itemCounts } deliveryCosts = { this . state . deliveryCosts } / >
< / p >
2016-01-12 14:23:40 +01:00
2016-01-13 09:51:36 +01:00
< div className = "hidden-xs" >
< button className = "btn btn-default gift-btn" onClick = { this . _onGiftBtnClicked } > Poklon < / b u t t o n >
< br / >
< p className = "collapsed-address-container" > { last _used _payment } ili < button className = "btn btn-default" onClick = { this . _onUncolapseClick } > Promijeni način plaćanja ili adresu < / b u t t o n > < / p >
< / d i v >
2016-01-12 14:23:40 +01:00
2016-01-13 09:51:36 +01:00
< div className = "collapsed-address-container-mobile btn-group-vertical visible-xs" >
< button className = "btn btn-default" onClick = { this . _onGiftBtnClicked } > Poklon < / b u t t o n >
{ last _used _payment }
< button className = "btn btn-default" onClick = { this . _onUncolapseClick } > Promijeni način plaćanja ili adresu < / b u t t o n >
< / d i v >
2016-01-12 14:23:40 +01:00
2015-06-14 06:18:10 +02:00
< div className = "form-group" >
< label className = "col-md-4 control-label" htmlFor = "order" > < / l a b e l >
< div className = "col-md-8" >
< div > < / d i v >
< div > < / d i v >
< / d i v >
2015-11-14 04:39:05 +01:00
< / d i v >
2015-06-14 06:18:10 +02:00
< / d i v > ) ;
}
return content ;
2015-02-19 07:17:31 +01:00
} ,
// Add change listeners to stores
componentDidMount : function ( ) {
CartStore . addChangeListener ( this . _onChange ) ;
CartActions . load ( ) ;
} ,
componentWillUnmount : function ( ) {
CartStore . removeChangeListener ( this . _onChange ) ;
} ,
_onChange : function ( ) {
if ( this . isMounted ( ) ) {
this . setState ( CartStore . getWholeCartState ( ) ) ;
}
} ,
2015-02-23 07:08:23 +01:00
_onFieldChange : function ( event ) {
2016-01-11 16:03:53 +01:00
if ( event . target . name === "gift" ) {
CartActions . changeDeliveryDestinationProperty ( event . target . name , $ ( event . target ) . is ( ':checked' ) ) ;
} else {
CartActions . changeDeliveryDestinationProperty ( event . target . name , event . target . value ) ;
}
} ,
2015-02-26 06:48:34 +01:00
_onOrderClick : function ( event ) {
2016-01-11 10:52:18 +01:00
CartActions . changeDeliveryDestinationProperty ( "payment_method" , "cash_on_delivery" ) ;
2015-02-26 06:48:34 +01:00
CartActions . confirmDelivery ( ) ;
} ,
2015-02-19 07:17:31 +01:00
2015-06-14 06:18:10 +02:00
_onUncolapseClick : function ( event ) {
CartActions . setAddressColapsed ( false ) ;
} ,
2016-01-12 14:23:40 +01:00
_onGiftBtnClicked : function ( event ) {
CartActions . changeDeliveryDestinationProperty ( 'gift' , true ) ;
CartActions . setAddressColapsed ( false ) ;
} ,
2016-01-08 10:21:33 +01:00
_handleOnSubmitPaypal : function ( event ) {
CartActions . changeDeliveryDestinationProperty ( 'payment_method' , 'paypal' ) ;
return false ;
} ,
2015-02-19 07:17:31 +01:00
getInitialState : function ( ) {
return CartStore . getWholeCartState ( ) ;
}
} ) ;
2016-01-06 08:26:19 +01:00
module . exports = CheckoutPage ;