refactor conditionals in template

This commit is contained in:
Ruidy 2024-03-10 19:54:56 +01:00
parent 8201b16f63
commit fef6ba4954
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
6 changed files with 136 additions and 151 deletions

View file

@ -41,14 +41,18 @@ func handleRequestBooking() echo.HandlerFunc {
errs = append(errs, "missing_communication_method") errs = append(errs, "missing_communication_method")
} }
return renderTempl(c, http.StatusOK, view.RequestBookingForm(&view.RequestBookingViewModel{ if len(errs) > 0 {
Item: itemStr, return renderTempl(c, http.StatusOK, view.RequestBookingForm(&view.RequestBookingViewModel{
From: fromStr, Item: itemStr,
To: toStr, From: fromStr,
Name: name, To: toStr,
PhoneNumber: phoneNumber, Name: name,
Email: email, PhoneNumber: phoneNumber,
Errors: errs, Email: email,
})) Errors: errs,
}))
}
return renderTempl(c, http.StatusSeeOther, view.BaseLayout())
} }
} }

View file

@ -44,7 +44,7 @@ func Index() templ.Component {
templ_7745c5c3_Buffer = templ.GetBuffer() templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<section><h1>Reserver votre sejour des maintenant</h1><article>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -60,7 +60,7 @@ func Index() templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</article></section>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }

View file

@ -32,11 +32,12 @@ templ Reports(months []string, m int, year string) {
Month Month
<select name="month" id="month" autofocus> <select name="month" id="month" autofocus>
for i, month := range months { for i, month := range months {
if i+1 == m { <option
<option value={ strconv.Itoa(i + 1) } selected>{ month } </option> value={ strconv.Itoa(i + 1) }
} else { if i+1 == m {
<option value={ strconv.Itoa(i + 1) }>{ month } </option> selected
} }
>{ month } </option>
} }
</select> </select>
</label> </label>

View file

@ -46,59 +46,41 @@ func Reports(months []string, m int, year string) templ.Component {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for i, month := range months { for i, month := range months {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(strconv.Itoa(i + 1)))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if i+1 == m { if i+1 == m {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" selected")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(strconv.Itoa(i + 1)))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" selected>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(month)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/reports.templ`, Line: 35, Col: 63}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(strconv.Itoa(i + 1)))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(month)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/reports.templ`, Line: 37, Col: 54}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(month)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/view/reports.templ`, Line: 39, Col: 16}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label></fieldset><button>Submit</button></form></section><section id=\"report\"></section>") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label></fieldset><button>Submit</button></form></section><section id=\"report\"></section>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {

View file

@ -45,11 +45,18 @@ templ RequestBookingForm(rbvm *RequestBookingViewModel) {
</label> </label>
<label for="to"> <label for="to">
Au Au
<input
type="date"
id="to"
name="to"
value={ rbvm.To }
required
if rbvm.invalidTimeRange() {
aria-invalid="true"
}
/>
if rbvm.invalidTimeRange() { if rbvm.invalidTimeRange() {
<input type="date" id="to" name="to" value={ rbvm.To } required aria-invalid="true"/>
<small>La date de depart doit etre apres celle d'arrivee</small> <small>La date de depart doit etre apres celle d'arrivee</small>
} else {
<input type="date" id="to" name="to" value={ rbvm.To } required/>
} }
</label> </label>
</fieldset> </fieldset>
@ -60,20 +67,30 @@ templ RequestBookingForm(rbvm *RequestBookingViewModel) {
</label> </label>
<label for="phone"> <label for="phone">
Telephone Telephone
<input
type="tel"
id="phone"
name="phone"
value={ rbvm.PhoneNumber }
if rbvm.missingCommunicationMethod() {
aria-invalid="true"
}
/>
if rbvm.missingCommunicationMethod() { if rbvm.missingCommunicationMethod() {
<input type="tel" id="phone" name="phone" value={ rbvm.PhoneNumber } aria-invalid="true"/>
<small>Veuillez renseigner votre numéro de télephone ou votre adresse email</small> <small>Veuillez renseigner votre numéro de télephone ou votre adresse email</small>
} else {
<input type="tel" id="phone" value={ rbvm.PhoneNumber } name="phone"/>
} }
</label> </label>
<label for="email"> <label for="email">
Email Email
if rbvm.missingCommunicationMethod() { <input
<input type="email" id="email" name="email" value={ rbvm.Email } aria-invalid="true"/> type="email"
} else { id="email"
<input type="email" id="email" name="email" value={ rbvm.Email }/> name="email"
} value={ rbvm.Email }
if rbvm.missingCommunicationMethod() {
aria-invalid="true"
}
/>
</label> </label>
</fieldset> </fieldset>
<label for="message"> <label for="message">

View file

@ -51,12 +51,12 @@ func RequestBookingForm(rbvm *RequestBookingViewModel) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent templ_7745c5c3_Var1 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 1) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form id=\"booking-request-form\" hx-post=\"/request-booking\"><fieldset class=\"grid\"><label for=\"item\">Logement <select name=\"item\" id=\"item\" required>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for _, i := range items { for _, i := range items {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 2) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<option value=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -64,7 +64,7 @@ func RequestBookingForm(rbvm *RequestBookingViewModel) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 3) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -77,12 +77,12 @@ func RequestBookingForm(rbvm *RequestBookingViewModel) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 4) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</option>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 5) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</select></label> <label for=\"from\">Du <input type=\"date\" id=\"from\" name=\"from\" value=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -90,38 +90,35 @@ func RequestBookingForm(rbvm *RequestBookingViewModel) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 6) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" required></label> <label for=\"to\">Au <input type=\"date\" id=\"to\" name=\"to\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(rbvm.To))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" required")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if rbvm.invalidTimeRange() { if rbvm.invalidTimeRange() {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 7) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" aria-invalid=\"true\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(rbvm.To))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 8)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 9)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(rbvm.To))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 10)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 11) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if rbvm.invalidTimeRange() {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<small>La date de depart doit etre apres celle d'arrivee</small>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label></fieldset><fieldset class=\"grid\"><label for=\"name\">Nom * <input type=\"text\" id=\"name\" name=\"name\" value=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -129,69 +126,53 @@ func RequestBookingForm(rbvm *RequestBookingViewModel) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 12) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" required></label> <label for=\"phone\">Telephone <input type=\"tel\" id=\"phone\" name=\"phone\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(rbvm.PhoneNumber))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if rbvm.missingCommunicationMethod() { if rbvm.missingCommunicationMethod() {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 13) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" aria-invalid=\"true\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(rbvm.PhoneNumber))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 14)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 15)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(rbvm.PhoneNumber))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 16)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 17) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("> ")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if rbvm.missingCommunicationMethod() { if rbvm.missingCommunicationMethod() {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 18) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<small>Veuillez renseigner votre numéro de télephone ou votre adresse email</small>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(rbvm.Email))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 19)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
} else {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 20)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(rbvm.Email))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 21)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 22) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</label> <label for=\"email\">Email <input type=\"email\" id=\"email\" name=\"email\" value=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(rbvm.Email))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if rbvm.missingCommunicationMethod() {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" aria-invalid=\"true\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("></label></fieldset><label for=\"message\">Message <textarea name=\"message\" id=\"message\"></textarea></label> <button type=\"submit\">Book</button></form>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }