Adding contact form for employers to contact candidates.

This commit is contained in:
Nick Winter 2014-04-10 14:59:32 -07:00
parent e9416ee128
commit 7a35a6248f
7 changed files with 101 additions and 25 deletions

View file

@ -1,16 +1,9 @@
module.exports.sendContactMessage = (contactMessageObject, modal) ->
modal.find('.sending-indicator').show()
jqxhr = $.post '/contact',
email: contactMessageObject.email
message: contactMessageObject.message
,
(response) ->
console.log "Got contact response:", response
modal.find('.sending-indicator').hide()
modal.find('#contact-message').val("Thanks!")
_.delay ->
modal.find('#contact-message').val("")
modal.modal 'hide'
, 1000
jqxhr = $.post '/contact', contactMessageObject, (response) ->
modal.find('.sending-indicator').hide()
modal.find('#contact-message').val("Thanks!")
_.delay ->
modal.find('#contact-message').val("")
modal.modal 'hide'
, 1000

View file

@ -3,6 +3,7 @@ module.exports = nativeDescription: "English", englishDescription: "English", tr
loading: "Loading..."
saving: "Saving..."
sending: "Sending..."
send: "Send"
cancel: "Cancel"
save: "Save"
create: "Create"
@ -111,6 +112,8 @@ module.exports = nativeDescription: "English", englishDescription: "English", tr
forum_page: "our forum"
forum_suffix: " instead."
send: "Send Feedback"
contact_candidate: "Contact Candidate"
recruitment_reminder: "Use this form to get in touch with candidates you are interested in interviewing. Remember that CodeCombat charges 18% of first-year salary for any full-time candidate you hire who stays 90 days, but that part-timers, remote employees, contractors, and interns are free."
diplomat_suggestion:
title: "Help translate CodeCombat!"
@ -331,6 +334,7 @@ module.exports = nativeDescription: "English", englishDescription: "English", tr
results: "Results"
description: "Description"
or: "or"
subject: "Subject"
email: "Email"
password: "Password"
message: "Message"

View file

@ -0,0 +1,22 @@
extends /templates/modal/contact
block modal-header-content
h3(data-i18n="contact.contact_candidate") Contact Candidate
block modal-body-content
p(data-i18n="contact.recruitment_reminder") Use this form to get in touch with candidates you are interested in interviewing. Remember that CodeCombat charges 18% of first-year salary for any full-time candidate you hire who stays 90 days, but that part-timers, remote employees, contractors, and interns are free.
.form
.form-group
label.control-label(for="contact-email", data-i18n="general.email") Email
input#contact-email.form-control(name="email", type="email", value=me.get('email'), placeholder="Where should the candidate reply?")
.form-group
label.control-label(for="contact-subject", data-i18n="general.subject") Subject
input#contact-subject.form-control(name="subject", type="text", value="Job interest", placeholder="Subject of the email the candidate will receive.")
.form-group
label.control-label(for="contact-message", data-i18n="general.message") Message
textarea#contact-message.form-control(name="message", rows=8)
block modal-footer-content
span.sending-indicator.pull-left.secret(data-i18n="common.sending") Sending...
a(href='#', data-dismiss="modal", aria-hidden="true", data-i18n="common.cancel").btn Cancel
button.btn.btn-primary#contact-submit-button(data-i18n="common.send") Send

View file

@ -1,6 +1,7 @@
View = require 'views/kinds/RootView'
template = require 'templates/account/profile'
User = require 'models/User'
JobProfileContactView = require 'views/modal/job_profile_contact_modal'
module.exports = class ProfileView extends View
id: "profile-view"
@ -9,6 +10,7 @@ module.exports = class ProfileView extends View
events:
'click #toggle-job-profile-approved': 'toggleJobProfileApproved'
'keyup #job-profile-notes': 'onJobProfileNotesChanged'
'click #contact-candidate': 'onContactCandidate'
constructor: (options, @userID) ->
@onJobProfileNotesChanged = _.debounce @onJobProfileNotesChanged, 1000
@ -65,3 +67,6 @@ module.exports = class ProfileView extends View
icon.url = "/images/pages/account/profile/icon_#{icon.icon}.png"
return icon
null
onContactCandidate: (e) ->
@openModalView new JobProfileContactView recipientID: @user.id

View file

@ -6,16 +6,15 @@ forms = require 'lib/forms'
contactSchema =
additionalProperties: false
required: ['email', 'message']
properties:
email:
required: true
type: 'string'
maxLength: 100
minLength: 1
format: 'email'
message:
required: true
type: 'string'
minLength: 1

View file

@ -0,0 +1,41 @@
ContactView = require 'views/modal/contact_modal'
template = require 'templates/modal/job_profile_contact'
forms = require 'lib/forms'
{sendContactMessage} = require 'lib/contact'
contactSchema =
additionalProperties: false
required: ['email', 'message']
properties:
email:
type: 'string'
maxLength: 100
minLength: 1
format: 'email'
subject:
type: 'string'
minLength: 1
message:
type: 'string'
minLength: 1
recipientID:
type: 'string'
minLength: 1
module.exports = class JobProfileContactView extends ContactView
id: "job-profile-contact-modal"
template: template
contact: ->
forms.clearFormAlerts @$el
contactMessage = forms.formToObject @$el
contactMessage.recipientID = @options.recipientID
res = tv4.validateMultiple contactMessage, contactSchema
return forms.applyErrorsToForm @$el, res.errors unless res.valid
contactMessage.message += '\n\n\n\n[CodeCombat says: please let us know if you end up accepting this job. Thanks!]'
window.tracker?.trackEvent 'Sent Job Profile Message', message: contactMessage
sendContactMessage contactMessage, @$el

View file

@ -1,26 +1,38 @@
config = require '../../server_config'
log = require 'winston'
mail = require '../commons/mail'
User = require '../users/User'
module.exports.setup = (app) ->
app.post '/contact', (req, res) ->
return res.end() unless req.user
log.info "Sending mail from #{req.body.email} saying #{req.body.message}"
if config.isProduction
options = createMailOptions req.body.email, req.body.message, req.user
mail.transport.sendMail options, (error, response) ->
if error
log.error "Error sending mail: #{error.message or error}"
else
log.info "Mail sent successfully. Response: #{response.message}"
createMailOptions req.body.email, req.body.message, req.user, req.body.recipientID, req.body.subject, (options) ->
mail.transport.sendMail options, (error, response) ->
if error
log.error "Error sending mail: #{error.message or error}"
else
log.info "Mail sent successfully. Response: #{response.message}"
return res.end()
createMailOptions = (sender, message, user) ->
createMailOptions = (sender, message, user, recipientID, subject, done) ->
# TODO: use email templates here
options =
from: config.mail.username
to: config.mail.username
replyTo: sender
subject: "[CodeCombat] Feedback - #{sender}"
subject: "[CodeCombat] #{subject ? ('Feedback - ' + sender)}"
text: "#{message}\n\nUsername: #{user.get('name') or 'Anonymous'}\nID: #{user._id}"
#html: message.replace '\n', '<br>\n'
#html: message.replace '\n', '<br>\n'
if recipientID and (user.isAdmin() or ('employer' in (user.permissions ? [])))
User.findById(recipientID, 'email').exec (err, document) ->
if err
log.error "Error looking up recipient to email from #{recipientID}: #{err}" if err
else
options.bcc = options.to
options.to = document.get('email')
done options
else
done options