import React, { createRef } from "react"; import ShareURLComponent from "./share_url"; import _ from "underscore"; /** * Takes sequence accession as props, fetches the sequence from the server, and * displays it in a modal. */ export default class CloudShareModal extends React.Component { constructor(props) { super(props); this.state = { formState: 'input', // Possible values: 'input', 'loading', 'results', 'error' errorMessages: [], email: '', agreeToTos: false, shareableurl: '', }; this.modalRef = createRef(); } // Lifecycle methods. // handleChange = (e) => { const { name, value, type, checked } = e.target; const inputValue = type === 'checkbox' ? checked : value; this.setState({ [name]: inputValue }); } handleSubmit = (e) => { e.preventDefault(); const { email } = this.state; const regex = /\/([^/]+)(?:\/|#|\?|$)/; const match = window.location.pathname.match(regex); const jobId = match[1]; this.setState({ formState: 'loading' }); const requestData = { job_id: jobId, sender_email: email }; fetch('/cloud_share', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(requestData) }) .then(response => response.json()) .then(data => { if (data.shareable_url) { // Successful response this.setState({ formState: 'results', shareableurl: data.shareable_url }); } else if (data.errors) { // Error response with specific error messages const errorMessages = data.errors; this.setState({ formState: 'error', errorMessages }); } else { // Generic error message throw new Error('Unknown error submitting form'); } }) .catch(error => { this.setState({ formState: 'error', errorMessages: [error.message] }); }); } renderLoading() { return (
Uploading the job to SequenceServer Cloud, please wait...