improve phone field
This commit is contained in:
@@ -442,6 +442,7 @@ export default {
|
|||||||
isFormVisible: true,
|
isFormVisible: true,
|
||||||
currentStep: 0,
|
currentStep: 0,
|
||||||
isSubmitting: false,
|
isSubmitting: false,
|
||||||
|
submittedValues: {},
|
||||||
recalculateButtonDisabledKey: ''
|
recalculateButtonDisabledKey: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -493,6 +494,8 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
|
this.submittedValues = JSON.parse(JSON.stringify(this.values))
|
||||||
|
|
||||||
if (this.goToLast) {
|
if (this.goToLast) {
|
||||||
this.currentStep = Math.min(
|
this.currentStep = Math.min(
|
||||||
this.stepFields.indexOf([...this.stepFields].reverse().find((fields) => fields.some((f) => !!this.values[f.uuid]))) + 1,
|
this.stepFields.indexOf([...this.stepFields].reverse().find((fields) => fields.some((f) => !!this.values[f.uuid]))) + 1,
|
||||||
@@ -517,7 +520,10 @@ export default {
|
|||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.recalculateButtonDisabledKey = Math.random()
|
this.recalculateButtonDisabledKey = Math.random()
|
||||||
|
|
||||||
this.maybeTrackEmailClick().finally(() => {
|
Promise.all([
|
||||||
|
this.maybeTrackEmailClick(),
|
||||||
|
this.maybeTrackSmsClick()
|
||||||
|
]).finally(() => {
|
||||||
this.trackViewForm()
|
this.trackViewForm()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -548,6 +554,30 @@ export default {
|
|||||||
return Promise.resolve({})
|
return Promise.resolve({})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
maybeTrackSmsClick () {
|
||||||
|
const queryParams = new URLSearchParams(window.location.search)
|
||||||
|
|
||||||
|
if (queryParams.has('c')) {
|
||||||
|
const c = queryParams.get('c')
|
||||||
|
|
||||||
|
queryParams.delete('c')
|
||||||
|
const newUrl = [window.location.pathname, queryParams.toString()].filter(Boolean).join('?')
|
||||||
|
window.history.replaceState({}, document.title, newUrl)
|
||||||
|
|
||||||
|
return fetch(this.baseUrl + '/api/submitter_sms_clicks', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
c,
|
||||||
|
submitter_slug: this.submitterSlug
|
||||||
|
})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return Promise.resolve({})
|
||||||
|
}
|
||||||
|
},
|
||||||
trackViewForm () {
|
trackViewForm () {
|
||||||
fetch(this.baseUrl + '/api/submitter_form_views', {
|
fetch(this.baseUrl + '/api/submitter_form_views', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -594,9 +624,13 @@ export default {
|
|||||||
: () => Promise.resolve({})
|
: () => Promise.resolve({})
|
||||||
|
|
||||||
stepPromise().then(async () => {
|
stepPromise().then(async () => {
|
||||||
|
const emptyRequiredField = this.stepFields.find((fields, index) => {
|
||||||
|
return index < this.currentStep && fields[0].required && fields[0].type === 'phone' && !this.submittedValues[fields[0].uuid]
|
||||||
|
})
|
||||||
|
|
||||||
const formData = new FormData(this.$refs.form)
|
const formData = new FormData(this.$refs.form)
|
||||||
|
|
||||||
if (this.currentStep === this.stepFields.length - 1) {
|
if (this.currentStep === this.stepFields.length - 1 && !emptyRequiredField) {
|
||||||
formData.append('completed', 'true')
|
formData.append('completed', 'true')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,10 +643,12 @@ export default {
|
|||||||
return Promise.reject(new Error(data.error))
|
return Promise.reject(new Error(data.error))
|
||||||
}
|
}
|
||||||
|
|
||||||
const nextStep = this.stepFields[this.currentStep + 1]
|
this.submittedValues[this.currentField.uuid] = this.values[this.currentField.uuid]
|
||||||
|
|
||||||
|
const nextStep = emptyRequiredField || this.stepFields[this.currentStep + 1]
|
||||||
|
|
||||||
if (nextStep) {
|
if (nextStep) {
|
||||||
this.goToStep(this.stepFields[this.currentStep + 1], true)
|
this.goToStep(nextStep, true)
|
||||||
} else {
|
} else {
|
||||||
this.isCompleted = true
|
this.isCompleted = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class SubmissionEvent < ApplicationRecord
|
|||||||
open_email: 'open_email',
|
open_email: 'open_email',
|
||||||
click_email: 'click_email',
|
click_email: 'click_email',
|
||||||
click_sms: 'click_sms',
|
click_sms: 'click_sms',
|
||||||
|
phone_verified: 'phone_verified',
|
||||||
start_form: 'start_form',
|
start_form: 'start_form',
|
||||||
view_form: 'view_form',
|
view_form: 'view_form',
|
||||||
complete_form: 'complete_form'
|
complete_form: 'complete_form'
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ module ReplaceEmailVariables
|
|||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def call(text, submitter:)
|
def call(text, submitter:, tracking_event_type: 'click_email')
|
||||||
submitter_link = build_submitter_link(submitter)
|
submitter_link = build_submitter_link(submitter, tracking_event_type)
|
||||||
|
|
||||||
submission_link = build_submission_link(submitter.submission) if submitter.submission
|
submission_link = build_submission_link(submitter.submission) if submitter.submission
|
||||||
|
|
||||||
@@ -43,12 +43,20 @@ module ReplaceEmailVariables
|
|||||||
end.join
|
end.join
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_submitter_link(submitter)
|
def build_submitter_link(submitter, tracking_event_type)
|
||||||
Rails.application.routes.url_helpers.submit_form_url(
|
if tracking_event_type == 'click_email'
|
||||||
slug: submitter.slug,
|
Rails.application.routes.url_helpers.submit_form_url(
|
||||||
t: SubmissionEvents.build_tracking_param(submitter, 'click_email'),
|
slug: submitter.slug,
|
||||||
**Docuseal.default_url_options
|
t: SubmissionEvents.build_tracking_param(submitter, 'click_email'),
|
||||||
)
|
**Docuseal.default_url_options
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Rails.application.routes.url_helpers.submit_form_url(
|
||||||
|
slug: submitter.slug,
|
||||||
|
c: SubmissionEvents.build_tracking_param(submitter, 'click_sms'),
|
||||||
|
**Docuseal.default_url_options
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_submission_link(submission)
|
def build_submission_link(submission)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ module SubmissionEvents
|
|||||||
open_email: 'Email opened',
|
open_email: 'Email opened',
|
||||||
click_email: 'Email link clicked',
|
click_email: 'Email link clicked',
|
||||||
click_sms: 'SMS link clicked',
|
click_sms: 'SMS link clicked',
|
||||||
|
phone_verified: 'Phone verified',
|
||||||
start_form: 'Submission started',
|
start_form: 'Submission started',
|
||||||
view_form: 'Form viewed',
|
view_form: 'Form viewed',
|
||||||
complete_form: 'Submission completed'
|
complete_form: 'Submission completed'
|
||||||
|
|||||||
@@ -239,10 +239,10 @@ module Submissions
|
|||||||
{ text: SubmissionEvents::EVENT_NAMES[event.event_type.to_sym],
|
{ text: SubmissionEvents::EVENT_NAMES[event.event_type.to_sym],
|
||||||
font: [FONT_BOLD_NAME, { variant: :bold }] },
|
font: [FONT_BOLD_NAME, { variant: :bold }] },
|
||||||
event.event_type.include?('send_') ? ' to ' : ' by ',
|
event.event_type.include?('send_') ? ' to ' : ' by ',
|
||||||
if event.event_type.include?('sms')
|
if event.event_type.include?('sms') || event.event_type.include?('phone')
|
||||||
submitter.phone
|
submitter.phone
|
||||||
else
|
else
|
||||||
(submitter.email || submitter.name || submitter.phone)
|
(submitter.name || submitter.email || submitter.phone)
|
||||||
end
|
end
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ module Submitters
|
|||||||
def update_submitter!(submitter, params, request)
|
def update_submitter!(submitter, params, request)
|
||||||
values = normalized_values(params)
|
values = normalized_values(params)
|
||||||
|
|
||||||
validate_values!(values, submitter, params)
|
|
||||||
|
|
||||||
submitter.values.merge!(values)
|
submitter.values.merge!(values)
|
||||||
submitter.opened_at ||= Time.current
|
submitter.opened_at ||= Time.current
|
||||||
|
|
||||||
@@ -38,11 +36,15 @@ module Submitters
|
|||||||
submitter.completed_at = Time.current
|
submitter.completed_at = Time.current
|
||||||
submitter.ip = request.remote_ip
|
submitter.ip = request.remote_ip
|
||||||
submitter.ua = request.user_agent
|
submitter.ua = request.user_agent
|
||||||
|
|
||||||
SubmissionEvents.create_with_tracking_data(submitter, 'complete_form', request)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
submitter.save!
|
ApplicationRecord.transaction do
|
||||||
|
validate_values!(values, submitter, params, request)
|
||||||
|
|
||||||
|
SubmissionEvents.create_with_tracking_data(submitter, 'complete_form', request) if params[:completed] == 'true'
|
||||||
|
|
||||||
|
submitter.save!
|
||||||
|
end
|
||||||
|
|
||||||
submitter
|
submitter
|
||||||
end
|
end
|
||||||
@@ -59,15 +61,15 @@ module Submitters
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_values!(values, submitter, params)
|
def validate_values!(values, submitter, params, request)
|
||||||
values.each do |key, value|
|
values.each do |key, value|
|
||||||
field = submitter.submission.template_fields.find { |e| e['uuid'] == key }
|
field = submitter.submission.template_fields.find { |e| e['uuid'] == key }
|
||||||
|
|
||||||
validate_value!(value, field, params)
|
validate_value!(value, field, params, submitter, request)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_value!(_value, _field, _params)
|
def validate_value!(_value, _field, _params, _submitter, _request)
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user