This commit is contained in:
Martina 2020-09-16 16:30:55 -07:00
commit fab1318950
10 changed files with 158 additions and 41 deletions

View File

@ -219,3 +219,10 @@ export const getSerializedProfile = async (data) => {
body: JSON.stringify({ data }),
});
};
export const createSupportMessage = async (data) => {
return await returnJSON(`/api/support-message`, {
...DEFAULT_OPTIONS,
body: JSON.stringify({ data }),
});
};

View File

@ -53,6 +53,7 @@ const constructSlatesTreeForNavigation = (slates) => {
name: s.data.name || s.slatename,
pageTitle: `Viewing ${s.slatename}`,
decorator: "SLATE",
ignore: true,
};
});
};
@ -77,7 +78,7 @@ export const generate = ({ library = [], slates = [] }) => [
decorator: "SLATES",
name: "Slates",
pageTitle: "Slates",
children: constructSlatesTreeForNavigation(slates),
children: null,
},
{
id: "V1_NAVIGATION_SLATE",
@ -87,6 +88,7 @@ export const generate = ({ library = [], slates = [] }) => [
children: null,
ignore: true,
},
...constructSlatesTreeForNavigation(slates),
constructFilesTreeForNavigation(library),
/*
{

View File

@ -129,7 +129,7 @@ export const bytesToSize = (bytes, decimals = 2) => {
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${(bytes / Math.pow(k, i)).toFixed(dm)} ${sizes[i]}`;
return `${(bytes / Math.pow(k, i)).toFixed(dm)} ${sizes[i]}`;
};
export const getRemainingTime = (seconds) => {

View File

@ -2,7 +2,7 @@ import * as Strings from "~/common/strings";
const USERNAME_REGEX = new RegExp("^[a-zA-Z0-9_]{0,}[a-zA-Z]+[0-9]*$");
const MIN_PASSWORD_LENGTH = 8;
const EMAIL_REGEX = new RegExp("^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,}$");
const EMAIL_REGEX = /^[\w-]+@[a-zA-Z0-9_]+?\.[a-zA-Z]{2,50}$/;
// TODO(jim): Regex should cover some of this.
const REJECT_LIST = [

View File

@ -331,10 +331,6 @@ export default class ApplicationPage extends React.Component {
return response;
};
_handleCancel = () => {
this._handleDismissSidebar();
};
_handleDeleteYourself = async () => {
// TODO(jim): Put this somewhere better for messages.
const message =
@ -625,7 +621,7 @@ export default class ApplicationPage extends React.Component {
sidebarLoading: this.state.sidebarLoading,
onSelectedChange: this._handleSelectedChange,
onSubmit: this._handleSubmit,
onCancel: this._handleCancel,
onCancel: this._handleDismissSidebar,
onRegisterFileLoading: this._handleRegisterFileLoading,
onUploadFile: this._handleUploadFile,
onSidebarLoading: this._handleSidebarLoading,

View File

@ -3,6 +3,7 @@ import * as Strings from "~/common/strings";
import * as Constants from "~/common/constants";
import * as System from "~/components/system";
import * as Validations from "~/common/validations";
import * as Actions from "~/common/actions";
import { dispatchCustomEvent } from "~/common/custom-events";
import { css } from "@emotion/react";
@ -63,40 +64,51 @@ export default class SidebarCreateSlate extends React.Component {
return;
}
// const response = await this.props.onSubmit({
// type: "CREATE_SLATE",
// name: this.state.name,
// public: this.state.public,
// body: this.state.body,
// });
const response = await Actions.createSupportMessage({
username: this.props.viewer.username,
name: this.state.name,
email: this.state.email,
message: this.state.message,
stored: Strings.bytesToSize(this.props.viewer.stats.bytes),
});
// if (!response) {
// dispatchCustomEvent({
// name: "create-alert",
// detail: {
// alert: {
// message:
// "We're having trouble sending your message right now. Please try again",
// },
// },
// });
// return;
// }
if (!response) {
dispatchCustomEvent({
name: "create-alert",
detail: {
alert: {
message:
"We're having trouble sending out your message right now. Please try again",
},
},
});
this.setState({ loading: false });
return;
}
// if (response.error) {
// dispatchCustomEvent({
// name: "create-alert",
// detail: { alert: { decorator: response.decorator } },
// });
// return;
// }
if (response.error) {
dispatchCustomEvent({
name: "create-alert",
detail: {
decorator: response.decorator,
},
});
this.setState({ loading: false });
return;
}
// this.setState({ loading: false });
// this.props.onAction({
// type: "NAVIGATE",
// value: response.slate.id,
// data: response.slate,
// });
dispatchCustomEvent({
name: "create-alert",
detail: {
alert: {
message: "Message sent. You'll hear from us shortly",
status: "INFO",
},
},
});
this.setState({ loading: false });
this.props.onCancel();
return;
};
_handleChange = (e) => {

View File

@ -24,7 +24,7 @@ const STYLES_TEXTAREA = css`
border: 0;
transition: 200ms ease all;
padding: 16px 24px 16px 24px;
box-shadow: 0 0 0 1px inset ${Constants.system.border};
box-shadow: 0 0 0 1px ${Constants.system.border} inset;
::placeholder {
/* Chrome, Firefox, Opera, Safari 10.1+ */

31
node_common/support.js Normal file
View File

@ -0,0 +1,31 @@
import * as Environment from "~/node_common/environment";
import * as Strings from "~/common/strings";
import { IncomingWebhook } from "@slack/webhook";
const url = `https://hooks.slack.com/services/${Environment.SUPPORT_SLACK_WEBHOOK_KEY}`;
const webhook = new IncomingWebhook(url);
export const sendSlackMessage = ({
username,
name,
email,
message,
stored,
}) => {
if (Strings.isEmpty(Environment.SUPPORT_SLACK_WEBHOOK_KEY)) {
return false;
}
const userProfileURL = `https://slate.host/${username}`;
const userURL = `<${userProfileURL}|${username}>`;
try {
webhook.send({
text: `\n*Username:* ${userURL} (${stored} stored)\n*Name:* ${name}\n*Email:* ${email}\n*Message:* ${message}`,
});
return true;
} catch (e) {
return false;
}
};

View File

@ -0,0 +1,69 @@
import * as Environment from "~/node_common/environment";
import * as Data from "~/node_common/data";
import * as Utilities from "~/node_common/utilities";
import * as Serializers from "~/node_common/serializers";
import * as Support from "~/node_common/support";
export default async (req, res) => {
const id = Utilities.getIdFromCookie(req);
if (!id) {
return res.status(500).send({ decorator: "SERVER_SUPPORT", error: true });
}
const user = await Data.getUserById({
id,
});
if (!user) {
return res
.status(404)
.send({ decorator: "SERVER_SUPPORT_USER_NOT_FOUND", error: true });
}
if (user.error) {
return res
.status(500)
.send({ decorator: "SERVER_SUPPORT_USER_NOT_FOUND", error: true });
}
if (!req.body.data) {
return res.status(500).send({
decorator: "SERVER_SUPPORT_NO_DATA_PROVIDED",
error: true,
});
}
if (!req.body.data.email) {
return res.status(500).send({
decorator: "SERVER_SUPPORT_MUST_PROVIDE_EMAIL",
error: true,
});
}
if (!req.body.data.message) {
return res.status(500).send({
decorator: "SERVER_SUPPORT_MUST_PROVIDE_MESSAGE",
error: true,
});
}
if (!req.body.data.username) {
return res.status(500).send({
decorator: "SERVER_SUPPORT_NO_DATA_PROVIDED",
error: true,
});
}
let status = await Support.sendSlackMessage(req.body.data);
if (status) {
return res.status(200).send({
decorator: "SERVER_SUPPORT",
data: true,
});
} else {
return res.status(500).send({
decorator: "SERVER_SUPPORT",
error: true,
});
}
};

View File

@ -71,7 +71,7 @@ export default class SceneFilesFolder extends React.Component {
_interval;
state = {
view: "list",
view: "grid",
startIndex: 0,
};