mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-11 13:16:50 +00:00
119 lines
2.9 KiB
Text
119 lines
2.9 KiB
Text
package view
|
|
|
|
import "github.com/rjNemo/rentease/config"
|
|
|
|
func makeItems() []string {
|
|
host := config.NewHost()
|
|
items := make([]string, 0, 2)
|
|
for _, i := range host.Items {
|
|
if i.Name == "T2" || i.Name == "T3" {
|
|
items = append(items, i.Name)
|
|
}
|
|
}
|
|
return items
|
|
}
|
|
|
|
var items = makeItems()
|
|
|
|
type RequestBookingViewModel struct {
|
|
Item string
|
|
From string
|
|
To string
|
|
Name string
|
|
PhoneNumber string
|
|
Email string
|
|
Errors []string
|
|
}
|
|
|
|
func (rbvm RequestBookingViewModel) invalidTimeRange() bool {
|
|
for _, e := range rbvm.Errors {
|
|
if e == "invalid_time_range" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (rbvm RequestBookingViewModel) missingCommunicationMethod() bool {
|
|
for _, e := range rbvm.Errors {
|
|
if e == "missing_communication_method" {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
templ RequestBookingForm(rbvm *RequestBookingViewModel) {
|
|
<form id="booking-request-form" hx-post="/request-booking">
|
|
<fieldset class="grid">
|
|
<label for="item">
|
|
Logement
|
|
<select name="item" id="item" required>
|
|
for _,i := range items {
|
|
<option value={ i }>{ i }</option>
|
|
}
|
|
</select>
|
|
</label>
|
|
<label for="from">
|
|
Du
|
|
<input type="date" id="from" name="from" value={ rbvm.From } required/>
|
|
</label>
|
|
<label for="to">
|
|
Au
|
|
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>
|
|
} else {
|
|
<input type="date" id="to" name="to" value={ rbvm.To } required/>
|
|
}
|
|
</label>
|
|
</fieldset>
|
|
<fieldset class="grid">
|
|
<label for="name">
|
|
Nom *
|
|
<input type="text" id="name" name="name" value={ rbvm.Name } required/>
|
|
</label>
|
|
<label for="phone">
|
|
Telephone
|
|
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>
|
|
} else {
|
|
<input type="tel" id="phone" value={ rbvm.PhoneNumber } name="phone"/>
|
|
}
|
|
</label>
|
|
<label for="email">
|
|
Email
|
|
if rbvm.missingCommunicationMethod() {
|
|
<input type="email" id="email" name="email" value={ rbvm.Email } aria-invalid="true"/>
|
|
} else {
|
|
<input type="email" id="email" name="email" value={ rbvm.Email }/>
|
|
}
|
|
</label>
|
|
</fieldset>
|
|
<label for="message">
|
|
Message
|
|
<textarea name="message" id="message"></textarea>
|
|
</label>
|
|
<button type="submit">Book</button>
|
|
</form>
|
|
}
|
|
|
|
templ Index() {
|
|
@PublicLayout() {
|
|
<section>
|
|
<h1>Reserver votre sejour des maintenant</h1>
|
|
<article>
|
|
@RequestBookingForm(&RequestBookingViewModel{
|
|
Item: "T2",
|
|
From: "",
|
|
To: "",
|
|
Name: "",
|
|
PhoneNumber: "",
|
|
Email: "",
|
|
Errors: nil,
|
|
})
|
|
</article>
|
|
</section>
|
|
}
|
|
}
|