Skip to content

Commit

Permalink
Fix TOT-231: Add "How did you hear about us" to on boarding
Browse files Browse the repository at this point in the history
  • Loading branch information
blopker committed Jan 8, 2025
1 parent aeab322 commit e7b0ef1
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.4 on 2025-01-08 01:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('onboard', '0007_alter_onboardmodel_hopes_and_more'),
]

operations = [
migrations.AddField(
model_name='onboardmodel',
name='referral_other',
field=models.CharField(blank=True, help_text='Please tell us more about how you found us', max_length=100, verbose_name='If other, please specify'),
),
migrations.AddField(
model_name='onboardmodel',
name='referral_source',
field=models.CharField(blank=True, choices=[('search', 'Search Results'), ('social', 'Social Media'), ('keeper', 'A Keeper'), ('pamphlet', 'Pamphlet'), ('blog', 'Blog'), ('newsletter', 'Newsletter'), ('dream', 'A Dream')], max_length=20, verbose_name='How did you hear about us?'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.4 on 2025-01-08 01:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('onboard', '0008_onboardmodel_referral_other_and_more'),
]

operations = [
migrations.AlterField(
model_name='onboardmodel',
name='referral_source',
field=models.CharField(blank=True, choices=[('default', "I'm not sure"), ('search', 'Search Results'), ('social', 'Social Media'), ('keeper', 'A Keeper'), ('pamphlet', 'Pamphlet'), ('blog', 'Blog'), ('newsletter', 'Newsletter'), ('dream', '✨A Dream✨'), ('other', 'Other')], max_length=20, verbose_name='How did you hear about us?'),
),
]
23 changes: 23 additions & 0 deletions totem/onboard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@


class OnboardModel(models.Model):
REFERRAL_CHOICES = [
("default", "I'm not sure"),
("search", "Search Results"),
("social", "Social Media"),
("keeper", "A Keeper"),
("pamphlet", "Pamphlet"),
("blog", "Blog"),
("newsletter", "Newsletter"),
("dream", "✨A Dream✨"),
("other", "Other"),
]
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
Expand All @@ -16,6 +27,18 @@ class OnboardModel(models.Model):
suggestions = models.TextField(blank=True, null=True, validators=[MaxLengthValidator(5000)])
hopes = models.TextField(blank=True, null=True, validators=[MaxLengthValidator(5000)])
internal_notes = models.TextField(blank=True, null=True, validators=[MaxLengthValidator(10000)])
referral_source = models.CharField(
max_length=20,
choices=REFERRAL_CHOICES,
verbose_name="How did you hear about us?",
blank=True, # Remove if you want to make it required
)
referral_other = models.CharField(
max_length=100,
blank=True,
verbose_name="If other, please specify",
help_text="Please tell us more about how you found us",
)

def __str__(self):
return f"Onboard: {self.user}"
Expand Down
49 changes: 45 additions & 4 deletions totem/onboard/templates/onboard/onboard_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ <h1 class="h1 py-5">Welcome!</h1>
{{ form.non_field_errors }}
{% csrf_token %}
<div class="pb-5">
<label for="{{ form.name.id_for_label }}">Name</label>
{{ form.name.errors }}
{{ form.name }}
<label for="{{ form.name.id_for_label }}"
>Name<span class="text-red-500">*</span></label
>
{{ form.name.errors }} {{ form.name }}
<p class="pt-1 text-xs">
Other people will see this, but you don't have to use your real
name. Add any pronouns in parentheses if you'd like.
</p>
</div>
<div class="pb-5">
<div>
<label for="{{ form.age.id_for_label }}">Age</label>
<label for="{{ form.age.id_for_label }}"
>Age<span class="text-red-500">*</span></label
>
</div>
{{ form.age.errors }}
<div class="w-[100px]">{{ form.age }}</div>
Expand All @@ -46,6 +49,20 @@ <h1 class="h1 py-5">Welcome!</h1>
Your feedback here will help inform us about new topics to offer.
</p>
</div>
<div class="pb-5">
<div>
<label for="{{ form.referral_source.id_for_label }}">
How did you hear about us? (Optional)
</label>
</div>
{{ form.referral_source.errors }} {{ form.referral_source }}
<div id="referral-other-container" class="mt-3 hidden">
{{ form.referral_other.errors }} {{ form.referral_other }}
</div>
<p class="pt-1 text-xs">
This helps us understand how to reach more people like you.
</p>
</div>
<div class="mt-10 text-center">
<button class="shimmer btn btn-primary m-auto w-full" type="submit">
Submit
Expand All @@ -54,4 +71,28 @@ <h1 class="h1 py-5">Welcome!</h1>
</form>
</div>
</div>

<script>
function showOtherField(value) {
const otherField = document.getElementById("referral-other-container")
const otherInput = document.getElementById("id_referral_other")

if (otherField) {
if (value === "other") {
otherField.style.display = "block"
otherField.required = true
otherInput.focus()
} else {
otherField.style.display = "none"
otherField.required = false
}
}
}
document.addEventListener("DOMContentLoaded", function () {
const selectField = document.getElementById("id_referral_source")
if (selectField) {
showOtherField(selectField.value)
}
})
</script>
{% endblock content %}
16 changes: 15 additions & 1 deletion totem/onboard/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime

from django.contrib.auth.decorators import login_required
from django.forms import CharField, Form, IntegerField, Textarea, TextInput
from django.forms import CharField, ChoiceField, Form, IntegerField, Select, Textarea, TextInput
from django.http import HttpRequest
from django.shortcuts import redirect, render

Expand All @@ -26,6 +26,20 @@ class OnboardForm(Form):
)
age = IntegerField(required=True, initial=None, min_value=13, max_value=120, widget=TextInput())
hopes = CharField(max_length=1000, required=False, widget=Textarea(attrs={"rows": 3}))
referral_source = ChoiceField(
choices=OnboardModel.REFERRAL_CHOICES,
required=False,
widget=Select(attrs={"class": "form-select", "onchange": "showOtherField(this.value)"}),
)
referral_other = CharField(
max_length=100,
required=False,
widget=TextInput(
attrs={
"placeholder": "Please tell us more about how you found us",
}
),
)

def save(self, user: User, onboard: OnboardModel):
user.name = self.cleaned_data.pop("name")
Expand Down

0 comments on commit e7b0ef1

Please sign in to comment.