Update manual Volunteer entry.
This commit is contained in:
parent
c03498b59e
commit
3429ee92fe
2 changed files with 18 additions and 6 deletions
|
|
@ -13,6 +13,7 @@
|
|||
let showAdd = $state(false)
|
||||
let adding = $state(false)
|
||||
let newName = $state('')
|
||||
let newTicketName = $state('')
|
||||
let newEmail = $state('')
|
||||
let newDeptID = $state('')
|
||||
let newIsLead = $state(false)
|
||||
|
|
@ -89,6 +90,7 @@
|
|||
try {
|
||||
const data = {
|
||||
name: newName,
|
||||
ticket_name: newTicketName,
|
||||
email: newEmail,
|
||||
is_lead: newIsLead,
|
||||
note: newNote,
|
||||
|
|
@ -97,7 +99,7 @@
|
|||
const v = await api.volunteers.create(data)
|
||||
await db.volunteers.put(v)
|
||||
showAdd = false
|
||||
newName = newEmail = newNote = ''
|
||||
newName = newEmail = newTicketName = newNote = ''
|
||||
newDeptID = ''
|
||||
newIsLead = false
|
||||
} catch (err) {
|
||||
|
|
@ -180,8 +182,12 @@
|
|||
<form onsubmit={addVolunteer}>
|
||||
<div class="form-grid" style="display:grid;grid-template-columns:1fr 1fr;gap:1rem">
|
||||
<div class="form-group">
|
||||
<label for="v-name">Name *</label>
|
||||
<input id="v-name" bind:value={newName} required placeholder="Full name" />
|
||||
<label for="v-name">Preferred Name *</label>
|
||||
<input id="v-name" bind:value={newName} required placeholder="What they go by" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="v-ticket-name">Name on Ticket</label>
|
||||
<input id="v-ticket-name" bind:value={newTicketName} placeholder="Legal/ticketed name" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="v-email">Email</label>
|
||||
|
|
|
|||
|
|
@ -33,11 +33,15 @@ func (app *App) handleListVolunteers(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (app *App) handleCreateVolunteer(w http.ResponseWriter, r *http.Request) {
|
||||
var v Volunteer
|
||||
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
|
||||
var body struct {
|
||||
Volunteer
|
||||
TicketName string `json:"ticket_name"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
writeError(w, "invalid request", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
v := body.Volunteer
|
||||
if v.Name == "" {
|
||||
writeError(w, "name is required", http.StatusBadRequest)
|
||||
return
|
||||
|
|
@ -52,7 +56,9 @@ func (app *App) handleCreateVolunteer(w http.ResponseWriter, r *http.Request) {
|
|||
if v.Email != "" && v.ParticipantID == nil {
|
||||
p, _ := app.getParticipantByEmail(v.Email)
|
||||
if p == nil {
|
||||
p, _ = app.createParticipant(Participant{PreferredName: v.Name, Email: v.Email})
|
||||
p, _ = app.createParticipant(Participant{PreferredName: v.Name, Email: v.Email, TicketName: body.TicketName})
|
||||
} else if body.TicketName != "" && p.TicketName == "" {
|
||||
app.db.Exec(`UPDATE participants SET ticket_name = ?, updated_at = ? WHERE id = ?`, body.TicketName, now(), p.ID)
|
||||
}
|
||||
if p != nil {
|
||||
v.ParticipantID = &p.ID
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue