Compare commits

...

5 Commits

Author SHA1 Message Date
sovanna 5703458586 feat(issue19-22/UI): Updates shop build 2020-04-15 10:47:03 +09:00
sovanna 0758e2d2ba feat(issue22): Sends confirmation email to client
Also, adds the JSON configuration in order to be sent to the client
as a "reminder" of what he sends
2020-04-15 10:41:40 +09:00
sovanna a61ebbdff6 feat(issue22/server-flask): Adds reply_to
`recipient` refers to FLASK_MAIL_RECIPIENT env var
which is the email address that receives all RFQ
2020-04-15 10:25:05 +09:00
sovanna 44b361893f feat(issue19/UI): Removes deactivation button after form submit 2020-04-15 10:21:31 +09:00
sovanna e116bbf028 feat(issue22/servver-flask): Removes CORS 2020-04-15 10:19:03 +09:00
6 changed files with 32 additions and 22 deletions

View File

@ -1,5 +1,4 @@
from flask import Flask
from flask_cors import CORS
from flask_mail import Mail
from werkzeug.middleware.proxy_fix import ProxyFix
@ -20,12 +19,4 @@ def create_app(cfg=config):
app.register_blueprint(bp_api)
CORS(
app,
resources={r'/api/*': {
'methods': ['POST', 'OPTIONS'],
'allow_origins': app.config['CORS_ALLOWED_ORIGINS'].split(','),
'allow_headers': app.config['CORS_ALLOWED_HEADERS'].split(','),
}})
return app

View File

@ -8,6 +8,13 @@ from app.api import bp
from app import mail
@bp.after_request
def after(response):
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Headers"] = "*"
return response
@bp.route("/rfq", methods=["POST"])
def send_rfq():
payload = request.json
@ -25,16 +32,36 @@ def send_rfq():
resp = jsonify(error="missing body")
return make_response(resp, 400)
if "configuration" not in payload:
resp = jsonify(error="missing configuration")
return make_response(resp, 400)
recipient = current_app.config["MAIL_RECIPIENT"]
msg = Message(
"[ORDER HARDWARE - RFQ from %s]" % payload['email'],
reply_to=recipient,
sender=payload["email"],
recipients=[recipient])
msg.body = payload["body"]
msg.html = payload["body"]
mail.send(msg)
msg_client_confirmation = Message(
"[M-Labs - Order Hardware]",
reply_to=recipient,
sender=recipient,
recipients=[payload["email"]])
msg_client_confirmation.body = "Hello! We've received your request and " \
"will be in contact soon. " \
"Here is a reminder of your configuration: {}" \
"Thank you!".format(payload["configuration"])
msg_client_confirmation.html = "Hello!<br />" \
"We've received your request and will be in contact soon.<br />" \
"Here is a reminder of your configuration: {}<br /><br />" \
"Thank you!".format(payload["configuration"])
with mail.connect() as conn:
conn.send(msg)
conn.send(msg_client_confirmation)
return jsonify("ok")

View File

@ -16,6 +16,3 @@ MAIL_USERNAME = getenv("FLASK_MAIL_USERNAME")
MAIL_PASSWORD = getenv("FLASK_MAIL_PASSWORD")
MAIL_RECIPIENT = getenv("FLASK_MAIL_RECIPIENT")
CORS_ALLOWED_ORIGINS = getenv("FLASK_CORS_ORIGINS")
CORS_ALLOWED_HEADERS = getenv("FLASK_CORS_ALLOW_HEADERS")

View File

@ -1,7 +1,6 @@
blinker==1.4
click==7.1.1
Flask==1.1.2
Flask-Cors==3.0.7
Flask-Mail==0.9.1
itsdangerous==1.1.0
Jinja2==2.11.1

View File

@ -1220,9 +1220,7 @@ class OrderForm extends React.PureComponent {
value="Show configurations"
onClick={onClickShow} />
<input className="btn btn-primary w-100 m-0 ml-sm-2" style={Object.assign({}, isProcessingComplete ? {
'backgroundColor': 'gray',
} : {})} disabled={isProcessingComplete} type="submit" value={`${isProcessing ? 'Processing ...' : 'Request quote'}`} />
<input className="btn btn-primary w-100 m-0 ml-sm-2" type="submit" value={`${isProcessing ? 'Processing ...' : 'Request quote'}`} />
</div>
{/*This will open an email window. Send the email to make your request.*/}
</form>
@ -1862,6 +1860,7 @@ class Shop extends React.PureComponent {
axios.post(data.API_RFQ, {
email,
body,
configuration: JSON.stringify(crate),
headers: {'X-MLABS-OH': 'rlebcleu'}
}).then(response => {
this.setState({

View File

@ -1274,10 +1274,6 @@ function (_React$PureComponent9) {
onClick: onClickShow
}), React.createElement("input", {
className: "btn btn-primary w-100 m-0 ml-sm-2",
style: Object.assign({}, isProcessingComplete ? {
'backgroundColor': 'gray'
} : {}),
disabled: isProcessingComplete,
type: "submit",
value: "".concat(isProcessing ? 'Processing ...' : 'Request quote')
}))));
@ -1899,6 +1895,7 @@ function (_React$PureComponent12) {
axios.post(data.API_RFQ, {
email: email,
body: body,
configuration: JSON.stringify(crate),
headers: {
'X-MLABS-OH': 'rlebcleu'
}