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