diff --git a/js/components/whitelabel/prize/constants/prize_api_urls.js b/js/components/whitelabel/prize/constants/prize_api_urls.js index e493cffd..cb4e2e44 100644 --- a/js/components/whitelabel/prize/constants/prize_api_urls.js +++ b/js/components/whitelabel/prize/constants/prize_api_urls.js @@ -2,6 +2,7 @@ import AppPrizeConstants from './prize_application_constants'; + function getPrizeApiUrls(subdomain) { return { 'users_login': AppPrizeConstants.prizeApiEndpoint + subdomain + '/users/login/', @@ -21,7 +22,6 @@ function getPrizeApiUrls(subdomain) { 'select_piece': AppPrizeConstants.prizeApiEndpoint + subdomain + '/ratings/${piece_id}/select/', 'notes': AppPrizeConstants.prizeApiEndpoint + subdomain + '/notes/', 'note': AppPrizeConstants.prizeApiEndpoint + subdomain + '/notes/${piece_id}/' - }; } diff --git a/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js b/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js index 0150d67e..e8063f8b 100644 --- a/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js +++ b/js/components/whitelabel/prize/portfolioreview/components/pr_forms/pr_register_piece_form.js @@ -5,30 +5,107 @@ import React from 'react'; import Form from '../../../../../ascribe_forms/form'; import Property from '../../../../../ascribe_forms/property'; import InputTextAreaToggable from '../../../../../ascribe_forms/input_textarea_toggable'; -import InputCheckbox from '../../../../../ascribe_forms/input_checkbox'; import UploadFileButton from '../../../../../ascribe_buttons/upload_file_button'; +import GlobalNotificationModel from '../../../../../../models/global_notification_model'; +import GlobalNotificationActions from '../../../../../../actions/global_notification_actions'; + import AppConstants from '../../../../../../constants/application_constants'; +import ApiUrls from '../../../../../../constants/api_urls'; + +import requests from '../../../../../../utils/requests'; import { getLangText } from '../../../../../../utils/lang_utils'; +import { setCookie } from '../../../../../../utils/fetch_api_utils'; const { object } = React.PropTypes; const PRRegisterPieceForm = React.createClass({ propTypes: { - location: object + location: object, + history: object, + currentUser: object }, getInitialState(){ return { - isUploadReady: false + isUploadReady: false, + piece: null }; }, - handleSuccess() { + /** + * In this method, we're composing all fields on the page + * in two steps, first submitting the registration of the piece and + * second adding all the additional details + */ + submit() { + const { currentUser } = this.props; + const { registerPieceForm, + digitalWorkForm, + proofOfPaymentForm, + supportingMaterialsForm, + additionalDataForm } = this.refs; + const additionalDataFormData = additionalDataForm.getFormData(); + // composing data for piece registration + let registerPieceFormData = registerPieceForm.getFormData(); + registerPieceFormData.digital_work_key = digitalWorkForm.state.file ? digitalWorkForm.state.file.key : ''; + registerPieceFormData.terms = true; + + // submitting the piece + requests + .post(ApiUrls.pieces_list, { body: registerPieceFormData }) + .then(({ success, piece, notification }) => { + if(success) { + this.setState({ + piece + }, () => { + supportingMaterialsForm.createBlobRoutine(); + proofOfPaymentForm.createBlobRoutine(); + //thumbnailForm.createBlobRoutine(); + }); + + setCookie(currentUser.email, piece.id); + + return requests.post(ApiUrls.piece_extradata, { + body: { + extradata: additionalDataFormData, + piece_id: piece.id + }, + piece_id: piece.id + }); + } else { + const notificationMessage = new GlobalNotificationModel(notification, 'danger', 5000); + GlobalNotificationActions.appendGlobalNotification(notificationMessage); + } + }) + .catch((err) => { + console.log(err); + }); + + }, + + getCreateBlobRoutine(fileClass) { + const { piece } = this.state; + + if(piece && piece.id) { + if(fileClass === 'other_data') { + return { + url: ApiUrls.blob_otherdatas, + pieceId: piece.id + }; + } else if(fileClass === 'thumbnail') { + return { + url: ApiUrls.blob_thumbnail, + pieceId: piece.id + }; + } + } else { + return null; + } }, render() { @@ -37,8 +114,9 @@ const PRRegisterPieceForm = React.createClass({ return (
+ ref="registerPieceForm"> @@ -64,35 +142,40 @@ const PRRegisterPieceForm = React.createClass({ min={1} required/> -
-
- - - + placeholder={getLangText('Enter your statement')}/> + +
+
+ + + placeholder={getLangText('Enter exhibitions and publication history')}/>
{getLangText('Select the PDF with your work')} {getLangText('Featured Cover photo')} {getLangText('Supporting Materials (Optional)')} {getLangText('Proof of payment')}
+ buttons={{}} + className="ascribe-form-bordered"> - -  {getLangText('I agree to the Terms and Conditions of the Portfolio Review')} - + + + {getLangText('By submitting this form, you agree to the Terms of Service of Portfolio Review.')} +
diff --git a/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js b/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js index 5d1fd728..2d141866 100644 --- a/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js +++ b/js/components/whitelabel/prize/portfolioreview/components/pr_register_piece.js @@ -1,14 +1,19 @@ 'use strict'; import React from 'react'; +import { Link, History } from 'react-router'; import Col from 'react-bootstrap/lib/Col'; import Row from 'react-bootstrap/lib/Row'; +import UserStore from '../../../../../stores/user_store'; +import UserActions from '../../../../../actions/user_actions'; + import PRRegisterPieceForm from './pr_forms/pr_register_piece_form'; import { getLangText } from '../../../../../utils/lang_utils'; import { setDocumentTitle } from '../../../../../utils/dom_utils'; +import { getCookie } from '../../../../../utils/fetch_api_utils'; const { object } = React.PropTypes; @@ -18,7 +23,37 @@ const PRRegisterPiece = React.createClass({ location: object }, + mixins: [History], + + getInitialState() { + return UserStore.getState(); + }, + + componentDidMount() { + UserStore.listen(this.onChange); + UserActions.fetchCurrentUser(); + }, + + componentDidUpdate() { + const { currentUser } = this.state; + if(currentUser && currentUser.email) { + const submittedPieceId = getCookie(currentUser.email); + if(submittedPieceId) { + this.history.pushState(null, `/pieces/${submittedPieceId}`); + } + } + }, + + componentWillUnmount() { + UserStore.unlisten(this.onChange); + }, + + onChange(state) { + this.setState(state); + }, + render() { + const { currentUser } = this.state; const { location } = this.props; setDocumentTitle(getLangText('Submission form')); @@ -28,14 +63,25 @@ const PRRegisterPiece = React.createClass({

Portfolio Review

{getLangText('Submission closing on %s', ' 21 Dec 2015')}

-

{getLangText('Submissions are open to everyone, we accept only PDFs.')}

-

{getLangText('We accept only one PDF with up to 20 images from every participant.')}

-

{getLangText('You need to pay 50€ in order to apply. We only accept PayPal.')}

+

+ {getLangText('Submissions are open to everyone, we accept only PDFs.')} +

+

+ {getLangText('We accept only one PDF with up to 20 images from every participant.')} +

+

+ {getLangText('You need to pay 50€ in order to apply. We only accept PayPal.')} +

+

+ {getLangText("You're submitting as %s. ", currentUser.email)} + {getLangText('Change account?')} +

+ location={location} + currentUser={currentUser}/> ); diff --git a/js/components/whitelabel/prize/portfolioreview/pr_app.js b/js/components/whitelabel/prize/portfolioreview/pr_app.js index 072542f9..22a837be 100644 --- a/js/components/whitelabel/prize/portfolioreview/pr_app.js +++ b/js/components/whitelabel/prize/portfolioreview/pr_app.js @@ -1,7 +1,6 @@ 'use strict'; import React from 'react'; -import Footer from '../../../footer'; import GlobalNotification from '../../../global_notification'; import { getSubdomain } from '../../../../utils/general_utils'; @@ -26,7 +25,6 @@ let PrizeApp = React.createClass({ {children} -