saasitone/templ/pages/task.templ

56 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2024-07-17 19:58:58 -07:00
package pages
import (
"strconv"
"git.grosinger.net/tgrosinger/saasitone/templ/components"
"git.grosinger.net/tgrosinger/saasitone/pkg/form"
"git.grosinger.net/tgrosinger/saasitone/pkg/page"
)
type TaskForm struct {
Delay int `form:"delay" validate:"gte=0"`
Message string `form:"message" validate:"required"`
form.Submission
}
templ Task(p page.Page, f *TaskForm) {
if p.HTMX.Request.Target != "task" {
<article class="message is-link">
<div class="message-body">
<p>Submitting this form will create an <i>ExampleTask</i> in the task queue. After the specified delay, the message will be logged by the queue processor.</p>
<p>See pkg/tasks and the README for more information.</p>
</div>
</article>
}
@taskForm(p, f)
}
templ taskForm(p page.Page, f *TaskForm) {
<form id="task" method="post" hx-post={ p.ToURL("task.submit") }>
@components.Messages(p)
<div class="field">
<label for="delay" class="label">Delay (in seconds)</label>
<div class="control">
<input type="number" id="delay" name="delay" class={ "input", f.Submission.GetFieldStatusClass("Delay") } value={ strconv.Itoa(f.Delay) }/>
</div>
<p class="help">How long to wait until the task is executed</p>
@components.FieldErrors(f.Submission.GetFieldErrors("Delay"))
</div>
<div class="field">
<label for="message" class="label">Message</label>
<div class="control">
<textarea id="message" name="message" class={ "textarea", f.Submission.GetFieldStatusClass("Message") }>{ f.Message }</textarea>
</div>
<p class="help">The message the task will output to the log</p>
@components.FieldErrors(f.Submission.GetFieldErrors("Message"))
</div>
<div class="field is-grouped">
<div class="control">
<button class="button is-link">Add task to queue</button>
</div>
</div>
@components.CSRF(p.CSRF)
</form>
}