Skip to content

Commit 3650b92

Browse files
fix: endpoint disable when internal
1 parent 96d576b commit 3650b92

8 files changed

+408
-240
lines changed

web/components/endpoint_form.templ

+43-29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/ItsNotGoodName/smtpbridge/web/routes"
77
"github.com/ItsNotGoodName/smtpbridge/web/helpers"
8+
"github.com/ItsNotGoodName/smtpbridge/web/icons"
89
)
910

1011

@@ -27,16 +28,22 @@ type EndpointFormData struct {
2728
BodyTemplateError string
2829
Kind string
2930
KindError string
30-
EndpointFormConfigProps EndpointFormConfigProps
31+
EndpointFormConfigProps EndpointFormConfigProps
3132
}
3233

3334
templ EndpointForm(props EndpointFormProps) {
3435
<form hx-post={ props.Route().URLString() } class="flex flex-col gap-4" data-loading-states>
36+
if props.Data.Internal {
37+
<div class="alert alert-warning">
38+
@icons.Alert("h-6 w-6")
39+
<span>Endpoint cannot be edited because it is internal.</span>
40+
</div>
41+
}
3542
<div class="form-control">
3643
<label class="label">
3744
<span class="label-text">Name</span>
3845
</label>
39-
<input name="Name" type="text" placeholder="Name" class="input input-bordered" value={ props.Data.Name } />
46+
<input disabled?={ props.Data.Internal } name="Name" type="text" placeholder="Name" class="input input-bordered" value={ props.Data.Name } />
4047
if props.Data.NameError != "" {
4148
<label class="label">
4249
<span class="label-text-alt text-error">{ props.Data.NameError }</span>
@@ -45,17 +52,21 @@ templ EndpointForm(props EndpointFormProps) {
4552
</div>
4653
<div class="flex items-center justify-between">
4754
<div>Text Disable</div>
48-
<div><input name="TextDisable" type="checkbox" class="toggle" checked?={ props.Data.TextDisable } disabled?={ props.Data.Internal } /></div>
55+
<div>
56+
<input disabled?={ props.Data.Internal } name="TextDisable" type="checkbox" class="toggle" checked?={ props.Data.TextDisable } disabled?={ props.Data.Internal } />
57+
</div>
4958
</div>
5059
<div class="flex items-center justify-between">
5160
<div>Attachment Disable</div>
52-
<div><input name="AttachmentDisable" type="checkbox" class="toggle" checked?={ props.Data.AttachmentDisable } disabled?={ props.Data.Internal } /></div>
61+
<div>
62+
<input disabled?={ props.Data.Internal } name="AttachmentDisable" type="checkbox" class="toggle" checked?={ props.Data.AttachmentDisable } disabled?={ props.Data.Internal } />
63+
</div>
5364
</div>
5465
<div class="form-control">
5566
<label class="label">
5667
<span class="label-text">Title Template</span>
5768
</label>
58-
<textarea name="TitleTemplate" placeholder="Title Template" class="textarea textarea-bordered h-24">
69+
<textarea disabled?={ props.Data.Internal } name="TitleTemplate" placeholder="Title Template" class="textarea textarea-bordered h-24">
5970
{ props.Data.TitleTemplate }
6071
</textarea>
6172
if props.Data.TitleTemplateError != "" {
@@ -68,7 +79,7 @@ templ EndpointForm(props EndpointFormProps) {
6879
<label class="label">
6980
<span class="label-text">Body Template</span>
7081
</label>
71-
<textarea name="BodyTemplate" placeholder="Body Template" class="textarea textarea-bordered h-24">
82+
<textarea disabled?={ props.Data.Internal } name="BodyTemplate" placeholder="Body Template" class="textarea textarea-bordered h-24">
7283
{ props.Data.BodyTemplate }
7384
</textarea>
7485
if props.Data.BodyTemplateError != "" {
@@ -84,7 +95,7 @@ templ EndpointForm(props EndpointFormProps) {
8495
<span data-loading-class="loading loading-spinner loading-xs" data-loading-path={ routes.EndpointFormConfigComponent().URLString() }></span>
8596
</span>
8697
</label>
87-
<select name="Kind" class="select select-bordered" hx-get={ routes.EndpointFormConfigComponent().URLString() } hx-target="#endpoint-config">
98+
<select disabled?={ props.Data.Internal } name="Kind" class="select select-bordered" hx-get={ routes.EndpointFormConfigComponent().URLString() } hx-target="#endpoint-config">
8899
<option disabled selected?={ props.Data.Kind == "" }>Select Kind</option>
89100
for _, s := range helpers.EndpointSchema() {
90101
<option value={ s.Kind } selected?={ props.Data.Kind == s.Kind }>{ s.Name }</option>
@@ -97,7 +108,7 @@ templ EndpointForm(props EndpointFormProps) {
97108
}
98109
</div>
99110
@EndpointFormConfig(props.Data.EndpointFormConfigProps)
100-
<button type="submit" class="btn btn-primary btn-block" data-loading-disable>
111+
<button disabled?={ props.Data.Internal } type="submit" class="btn btn-primary btn-block" data-loading-disable>
101112
<span data-loading-class="loading loading-spinner loading-xs">
102113
if props.Create {
103114
Create Endpoint
@@ -113,6 +124,7 @@ templ EndpointForm(props EndpointFormProps) {
113124
}
114125

115126
type EndpointFormConfigProps struct {
127+
Internal bool
116128
Fields []EndpointFormConfigField
117129
Error string
118130
}
@@ -127,29 +139,31 @@ type EndpointFormConfigField struct {
127139

128140
templ EndpointFormConfig(props EndpointFormConfigProps) {
129141
<fieldset id="endpoint-config">
130-
<legend>Config</legend>
131-
if props.Error != "" {
132-
<p class="text-error">{props.Error}</p>
133-
}
134-
for i, f := range props.Fields {
135-
<div class="form-control">
136-
<label class="label">
137-
<span class="label-text">{ f.Name }</span>
138-
</label>
139-
<input type="hidden" name={ "Config." + strconv.Itoa(i) + ".Key" } value={ f.Key } />
140-
if f.Multiline{
141-
<textarea name={ "Config." + strconv.Itoa(i) + ".Value" } placeholder={ f.Name } class="textarea textarea-bordered h-24">
142-
{ f.Value }
143-
</textarea>
144-
} else {
145-
<input name={ "Config." + strconv.Itoa(i) + ".Value" } placeholder={ f.Name } type="text" class="input input-bordered" value={ f.Value } />
146-
}
147-
if f.Description != "" {
142+
if len(props.Fields) > 0 {
143+
<legend>Config</legend>
144+
if props.Error != "" {
145+
<p class="text-error">{props.Error}</p>
146+
}
147+
for i, f := range props.Fields {
148+
<div class="form-control">
148149
<label class="label">
149-
<span class="label-text-alt">{ f.Description }</span>
150+
<span class="label-text">{ f.Name }</span>
150151
</label>
151-
}
152-
</div>
152+
<input type="hidden" name={ "Config." + strconv.Itoa(i) + ".Key" } value={ f.Key } />
153+
if f.Multiline{
154+
<textarea disabled?={ props.Internal } name={ "Config." + strconv.Itoa(i) + ".Value" } placeholder={ f.Name } class="textarea textarea-bordered h-24">
155+
{ f.Value }
156+
</textarea>
157+
} else {
158+
<input disabled?={ props.Internal } name={ "Config." + strconv.Itoa(i) + ".Value" } placeholder={ f.Name } type="text" class="input input-bordered" value={ f.Value } />
159+
}
160+
if f.Description != "" {
161+
<label class="label">
162+
<span class="label-text-alt">{ f.Description }</span>
163+
</label>
164+
}
165+
</div>
166+
}
153167
}
154168
</fieldset>
155169
}

0 commit comments

Comments
 (0)