05/07 Phase 3: fixed staff creation error

This commit is contained in:
2026-05-07 16:00:27 -04:00
parent 61a1b83688
commit 959f54ed84
2 changed files with 16 additions and 19 deletions
+5 -5
View File
@@ -48,21 +48,21 @@ def create():
max_len = 6
if not name or not phone:
return render_template("tenant/staff/form.html", mode="create",
locations=locations, error="Name and phone are required.")
locations=locations, assigned_ids=set(), error="Name and phone are required.")
if not validate_passcode(passcode, min_len, max_len):
return render_template("tenant/staff/form.html", mode="create",
locations=locations,
locations=locations, assigned_ids=set(),
error=f"Passcode must be {min_len}{max_len} digits.")
if Staff.query.filter_by(tenant_id=g.tenant.id, phone=phone).filter(
Staff.deleted_at.is_(None)).first():
return render_template("tenant/staff/form.html", mode="create",
locations=locations,
locations=locations, assigned_ids=set(),
error="A staff member with that phone number already exists.")
allowed, err = plan_limit_check("staff")
if not allowed:
return render_template("tenant/staff/form.html", mode="create",
locations=locations, error=err)
locations=locations, assigned_ids=set(), error=err)
member = Staff(
tenant_id=g.tenant.id, name=name, phone=phone,
@@ -96,7 +96,7 @@ def create():
flash(f"Staff member \'{name}\' created.", "success")
return redirect(url_for("staff.index"))
return render_template("tenant/staff/form.html", mode="create", locations=locations)
return render_template("tenant/staff/form.html", mode="create", locations=locations, assigned_ids=set())
@staff_bp.route("/<int:staff_id>/edit", methods=["GET", "POST"])
+10 -13
View File
@@ -11,19 +11,17 @@
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<div class="mb-3">
<label class="form-label">Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" name="name"
value="{{ staff.name if staff else '' }}" required autofocus>
<input type="text" class="form-control" name="name" value="{{ staff.name if staff else '' }}" required
autofocus>
</div>
<div class="mb-3">
<label class="form-label">Phone <span class="text-danger">*</span></label>
<input type="tel" class="form-control" name="phone"
value="{{ staff.phone if staff else '' }}" required>
<input type="tel" class="form-control" name="phone" value="{{ staff.phone if staff else '' }}" required>
</div>
{% if mode == 'create' %}
<div class="mb-3">
<label class="form-label">Passcode (46 digits) <span class="text-danger">*</span></label>
<input type="password" class="form-control" name="passcode"
inputmode="numeric" maxlength="6" required>
<input type="password" class="form-control" name="passcode" inputmode="numeric" maxlength="6" required>
<div class="form-text">Staff will use this PIN to log in. Show it to them once, then discard it.</div>
</div>
{% endif %}
@@ -32,7 +30,7 @@
<label class="form-label">Job Type</label>
<select class="form-select" name="staff_type">
{% for t in ['full_time','part_time','seasonal','receptionist','salon_manager'] %}
<option value="{{ t }}" {{ 'selected' if staff and staff.staff_type == t }}>
<option value="{{ t }}" {{ 'selected' if staff and staff.staff_type==t }}>
{{ t.replace('_',' ').title() }}
</option>
{% endfor %}
@@ -42,7 +40,7 @@
<label class="form-label">Pay Type</label>
<select class="form-select" name="pay_type">
{% for t in ['hourly','salary','guarantee'] %}
<option value="{{ t }}" {{ 'selected' if staff and staff.pay_type == t }}>{{ t.title() }}</option>
<option value="{{ t }}" {{ 'selected' if staff and staff.pay_type==t }}>{{ t.title() }}</option>
{% endfor %}
</select>
</div>
@@ -51,17 +49,16 @@
<label class="form-label">Location Assignments</label>
{% for loc in locations %}
<div class="form-check">
<input class="form-check-input" type="checkbox" name="location_ids"
value="{{ loc.id }}" id="loc_{{ loc.id }}"
{{ 'checked' if loc.id in (assigned_ids or set()) }}>
<input class="form-check-input" type="checkbox" name="location_ids" value="{{ loc.id }}"
id="loc_{{ loc.id }}" {{ 'checked' if assigned_ids and loc.id in assigned_ids }}>
<label class="form-check-label" for="loc_{{ loc.id }}">{{ loc.name }}</label>
</div>
{% endfor %}
</div>
{% if mode == 'edit' %}
<div class="form-check form-switch mb-3">
<input class="form-check-input" type="checkbox" name="is_active" value="1"
id="is_active" {{ 'checked' if staff and staff.is_active }}>
<input class="form-check-input" type="checkbox" name="is_active" value="1" id="is_active" {{ 'checked' if
staff and staff.is_active }}>
<label class="form-check-label" for="is_active">Active</label>
</div>
{% endif %}