improve phone field
This commit is contained in:
@@ -442,6 +442,7 @@ export default {
|
||||
isFormVisible: true,
|
||||
currentStep: 0,
|
||||
isSubmitting: false,
|
||||
submittedValues: {},
|
||||
recalculateButtonDisabledKey: ''
|
||||
}
|
||||
},
|
||||
@@ -493,6 +494,8 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.submittedValues = JSON.parse(JSON.stringify(this.values))
|
||||
|
||||
if (this.goToLast) {
|
||||
this.currentStep = Math.min(
|
||||
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.recalculateButtonDisabledKey = Math.random()
|
||||
|
||||
this.maybeTrackEmailClick().finally(() => {
|
||||
Promise.all([
|
||||
this.maybeTrackEmailClick(),
|
||||
this.maybeTrackSmsClick()
|
||||
]).finally(() => {
|
||||
this.trackViewForm()
|
||||
})
|
||||
})
|
||||
@@ -548,6 +554,30 @@ export default {
|
||||
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 () {
|
||||
fetch(this.baseUrl + '/api/submitter_form_views', {
|
||||
method: 'POST',
|
||||
@@ -594,9 +624,13 @@ export default {
|
||||
: () => Promise.resolve({})
|
||||
|
||||
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)
|
||||
|
||||
if (this.currentStep === this.stepFields.length - 1) {
|
||||
if (this.currentStep === this.stepFields.length - 1 && !emptyRequiredField) {
|
||||
formData.append('completed', 'true')
|
||||
}
|
||||
|
||||
@@ -609,10 +643,12 @@ export default {
|
||||
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) {
|
||||
this.goToStep(this.stepFields[this.currentStep + 1], true)
|
||||
this.goToStep(nextStep, true)
|
||||
} else {
|
||||
this.isCompleted = true
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ class SubmissionEvent < ApplicationRecord
|
||||
open_email: 'open_email',
|
||||
click_email: 'click_email',
|
||||
click_sms: 'click_sms',
|
||||
phone_verified: 'phone_verified',
|
||||
start_form: 'start_form',
|
||||
view_form: 'view_form',
|
||||
complete_form: 'complete_form'
|
||||
|
||||
@@ -12,8 +12,8 @@ module ReplaceEmailVariables
|
||||
|
||||
module_function
|
||||
|
||||
def call(text, submitter:)
|
||||
submitter_link = build_submitter_link(submitter)
|
||||
def call(text, submitter:, tracking_event_type: 'click_email')
|
||||
submitter_link = build_submitter_link(submitter, tracking_event_type)
|
||||
|
||||
submission_link = build_submission_link(submitter.submission) if submitter.submission
|
||||
|
||||
@@ -43,12 +43,20 @@ module ReplaceEmailVariables
|
||||
end.join
|
||||
end
|
||||
|
||||
def build_submitter_link(submitter)
|
||||
Rails.application.routes.url_helpers.submit_form_url(
|
||||
slug: submitter.slug,
|
||||
t: SubmissionEvents.build_tracking_param(submitter, 'click_email'),
|
||||
**Docuseal.default_url_options
|
||||
)
|
||||
def build_submitter_link(submitter, tracking_event_type)
|
||||
if tracking_event_type == 'click_email'
|
||||
Rails.application.routes.url_helpers.submit_form_url(
|
||||
slug: submitter.slug,
|
||||
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
|
||||
|
||||
def build_submission_link(submission)
|
||||
|
||||
@@ -10,6 +10,7 @@ module SubmissionEvents
|
||||
open_email: 'Email opened',
|
||||
click_email: 'Email link clicked',
|
||||
click_sms: 'SMS link clicked',
|
||||
phone_verified: 'Phone verified',
|
||||
start_form: 'Submission started',
|
||||
view_form: 'Form viewed',
|
||||
complete_form: 'Submission completed'
|
||||
|
||||
@@ -239,10 +239,10 @@ module Submissions
|
||||
{ text: SubmissionEvents::EVENT_NAMES[event.event_type.to_sym],
|
||||
font: [FONT_BOLD_NAME, { variant: :bold }] },
|
||||
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
|
||||
else
|
||||
(submitter.email || submitter.name || submitter.phone)
|
||||
(submitter.name || submitter.email || submitter.phone)
|
||||
end
|
||||
]
|
||||
)
|
||||
|
||||
@@ -29,8 +29,6 @@ module Submitters
|
||||
def update_submitter!(submitter, params, request)
|
||||
values = normalized_values(params)
|
||||
|
||||
validate_values!(values, submitter, params)
|
||||
|
||||
submitter.values.merge!(values)
|
||||
submitter.opened_at ||= Time.current
|
||||
|
||||
@@ -38,11 +36,15 @@ module Submitters
|
||||
submitter.completed_at = Time.current
|
||||
submitter.ip = request.remote_ip
|
||||
submitter.ua = request.user_agent
|
||||
|
||||
SubmissionEvents.create_with_tracking_data(submitter, 'complete_form', request)
|
||||
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
|
||||
end
|
||||
@@ -59,15 +61,15 @@ module Submitters
|
||||
end
|
||||
end
|
||||
|
||||
def validate_values!(values, submitter, params)
|
||||
def validate_values!(values, submitter, params, request)
|
||||
values.each do |key, value|
|
||||
field = submitter.submission.template_fields.find { |e| e['uuid'] == key }
|
||||
|
||||
validate_value!(value, field, params)
|
||||
validate_value!(value, field, params, submitter, request)
|
||||
end
|
||||
end
|
||||
|
||||
def validate_value!(_value, _field, _params)
|
||||
def validate_value!(_value, _field, _params, _submitter, _request)
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user