Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DT-1144: Update Support URLs #2767

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/libs/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ export const fetchAny = async (...args) => {
return res;
};

export const getFileNameFromHttpResponse = (response) => {
const respHeaders = response.headers;
return respHeaders.get('Content-Disposition').split(';')[1].trim().split('=')[1];
};

export const reportError = async (url, status) => {
const msg = 'Error fetching response: '
.concat(JSON.stringify(url))
Expand Down
52 changes: 24 additions & 28 deletions src/libs/ajax/Support.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
import * as fp from 'lodash/fp';
import { Config } from '../config';
import { fetchAny } from '../ajax';

import {getApiUrl} from '../ajax';
import axios from 'axios';

export const Support = {
createTicket: (name, type, email, subject, description, attachmentToken, url) => {
const ticket = {};

ticket.request = {
requester: { name: name, email: email },
createTicket: (name, type, email, subject, description, attachmentToken, url) => {
return {
name: name,
type: type.toUpperCase(),
email: email,
subject: subject,
// BEWARE changing the following ids or values! If you change them then you must thoroughly test.
custom_fields: [
{ id: 360012744452, value: type },
{ id: 360007369412, value: description },
{ id: 360012744292, value: name },
{ id: 360012782111, value: email },
{ id: 360018545031, value: email }
],
comment: {
body: description + '\n\n------------------\nSubmitted from: ' + url,
uploads: attachmentToken
},
ticket_form_id: 360000669472
description: description,
url: url,
uploads: attachmentToken
};

return ticket;

},

createSupportRequest: async (ticket) => {
const res = await fetchAny('https://broadinstitute.zendesk.com/api/v2/requests.json', fp.mergeAll([Config.jsonBody(ticket), { method: 'POST' }]));
return await res;
const url = `${await getApiUrl()}/support/request`;
return await axios.post(url, ticket, {headers: {'Content-Type': 'application/json'}}).catch(
function (error) {
return Promise.reject(error.response);
}
);
},

uploadAttachment: async (file) => {
const res = await fetchAny('https://broadinstitute.zendesk.com/api/v2/uploads?filename=Attachment', fp.mergeAll([Config.attachmentBody(file), { method: 'POST' }]));
return (await res.json()).upload;
const url = `${await getApiUrl()}/support/upload`;
return await axios.post(url, file, {headers: {'Content-Type': 'application/binary'}}).catch(
function (error) {
return Promise.reject(error.response);
}
);
},

};
7 changes: 0 additions & 7 deletions src/libs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export const Config = {

getNihUrl: async () => (await getConfig()).nihUrl,

getGoogleClientId: async () => (await getConfig()).clientId,

getGAId: async () => (await getConfig()).gaId,

getErrorApiKey: async () => (await getConfig()).errorApiKey,
Expand Down Expand Up @@ -65,11 +63,6 @@ export const Config = {
headers: {'Content-Type': 'application/json'},
}),

attachmentBody: body => ({
body: body,
headers: {'Content-Type': 'application/binary'}
}),

};

export const Token = {
Expand Down
32 changes: 17 additions & 15 deletions src/pages/user_profile/RequestForm.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { useState } from 'react';
import { Support } from '../../libs/ajax/Support';
import { Notifications } from '../../libs/utils';
import { isNil } from 'lodash';
import { FormField, FormFieldTypes } from '../../components/forms/forms';
import {useState} from 'react';
import {Support} from '../../libs/ajax/Support';
import {Notifications} from '../../libs/utils';
import {isNil} from 'lodash';
import {FormField, FormFieldTypes} from '../../components/forms/forms';

export default function SupportRequestsPage(props) {

Expand Down Expand Up @@ -47,8 +47,8 @@ export default function SupportRequestsPage(props) {
await props.history.push('/profile');
};

const handleSupportRequestsChange = ({ key, value }) => {
let newSupportRequests = Object.assign({}, supportRequests, { [key]: value });
const handleSupportRequestsChange = ({key, value}) => {
let newSupportRequests = Object.assign({}, supportRequests, {[key]: value});
setSupportRequests(newSupportRequests);
const hasAnyRequests = possibleSupportRequests.some(request => newSupportRequests[request.key]);
setHasSupportRequests(hasAnyRequests);
Expand Down Expand Up @@ -91,7 +91,9 @@ export default function SupportRequestsPage(props) {
};

const ticket = Support.createTicket(
profile.profileName, ticketInfo.type, profile.email,
profile.profileName,
ticketInfo.type,
profile.email,
ticketInfo.subject,
ticketInfo.description,
ticketInfo.attachmentToken,
Expand All @@ -101,7 +103,7 @@ export default function SupportRequestsPage(props) {
const response = await Support.createSupportRequest(ticket);
if (response.status === 201) {
Notifications.showSuccess(
{ text: 'Sent Requests Successfully', layout: 'topRight', timeout: 1500 }
{text: 'Sent Requests Successfully', layout: 'topRight', timeout: 1500}
);
} else {
Notifications.showError({
Expand All @@ -111,7 +113,7 @@ export default function SupportRequestsPage(props) {
}
};

return <div style={{ padding: '25px 270px 0px 270px' }}>
return <div style={{padding: '25px 270px 0px 270px'}}>
<p
style={{
color: '#01549F',
Expand All @@ -130,7 +132,7 @@ export default function SupportRequestsPage(props) {
}}>
<h2
id='lbl_supportRequests'
style={{ ...headerStyle, marginTop: 0 }}>
style={{...headerStyle, marginTop: 0}}>
Which of the following are you looking to do?*
</h2>
{possibleSupportRequests.map((supportRequest) => {
Expand All @@ -141,9 +143,9 @@ export default function SupportRequestsPage(props) {
type={FormFieldTypes.CHECKBOX}
key={supportRequest.key}
id={supportRequest.key}
onChange={handleSupportRequestsChange} />;
onChange={handleSupportRequestsChange}/>;
})}
<div style={{ margin: '15px 0 10px' }}>
<div style={{margin: '15px 0 10px'}}>
Is there anything else you would like to request?
</div>
<FormField
Expand All @@ -152,13 +154,13 @@ export default function SupportRequestsPage(props) {
placeholder='Enter your request'
maxLength='512'
rows='3'
onChange={handleSupportRequestsChange} />
onChange={handleSupportRequestsChange}/>
</div>
<button
id='btn_save'
onClick={goToPrevPage}
className='f-left btn-primary btn-back'
style={{ marginTop: '50px' }}>
style={{marginTop: '50px'}}>
Back
</button>
<button
Expand Down
Loading