This commit is contained in:
Aritra Banik 2024-02-25 02:42:40 +05:30
parent 8f7a830182
commit f75e3b841d
4 changed files with 71 additions and 33 deletions

BIN
src/a3

Binary file not shown.

View File

@ -5,7 +5,7 @@ import
nimja/parser,
strutils,
strformat,
./a3pkg/[models, mics],
./a3pkg/[models, mics, htmx],
./a3c/[products, users, cart, orders]
"/" -> [get, post]:
@ -280,12 +280,8 @@ import
productName = ""
quantity = 0
# if productName == "" and email == "":
# ctx.redirect("/login")
var
country = cookies["c_country"]
# country = ctx.queryParams["c_country"]
firstName = cookies["c_fname"]
lastName = cookies["c_lname"]
address = cookies["c_address"]
@ -295,7 +291,6 @@ import
phone = cookies["c_phone"]
password1: string
# echo ctx.queryParams["c_country"]
echo cookies
try:
@ -371,6 +366,18 @@ import
compileTemplateFile(getScriptDir() / "a3a" / "checkout.nimja")
"/lname" -> post:
var lname = ctx.urlForm["c_lname"]
echo lname
var val: Validity
if lname == "":
val.message = "Last Name is Required"
val.class = "text-danger"
else:
val.message = ""
val.class = "text-success"
ctx.send sendLastName(lname, val)
"/contact" -> get:
var
@ -445,34 +452,34 @@ import
compileTemplateFile(getScriptDir() / "a3a" / "shop-single.nimja")
# "/thankyou" -> get:
# var
# email: string
# password: string
# products: seq[Products]
"/thankyou" -> get:
var
email: string
password: string
products: seq[Products]
# try:
# email = ctx.cookies["email"]
# password = ctx.cookies["password"]
# except:
# email = ""
# password = ""
try:
email = ctx.cookies["email"]
password = ctx.cookies["password"]
except:
email = ""
password = ""
# if email == "":
# ctx.redirect("/login")
# else:
# products = micsGetProducts(email, password)
if email == "":
ctx.redirect("/login")
else:
products = micsGetProducts(email, password)
# ctx &= initCookie("c_country", "")
# ctx &= initCookie("c_fname", "")
# ctx &= initCookie("c_lname", "")
# ctx &= initCookie("c_address", "")
# ctx &= initCookie("c_state_country", "")
# ctx &= initCookie("c_postal_zip", "")
# ctx &= initCookie("c_email_address", "")
# ctx &= initCookie("c_phone", "")
ctx &= initCookie("c_country", "")
ctx &= initCookie("c_fname", "")
ctx &= initCookie("c_lname", "")
ctx &= initCookie("c_address", "")
ctx &= initCookie("c_state_country", "")
ctx &= initCookie("c_postal_zip", "")
ctx &= initCookie("c_email_address", "")
ctx &= initCookie("c_phone", "")
# compileTemplateFile(getScriptDir() / "a3a" / "thankyou.nimja")
compileTemplateFile(getScriptDir() / "a3a" / "thankyou.nimja")
"/login" -> get:
var

View File

@ -108,10 +108,16 @@
<label class="text-danger">{{firstNameError}}</label>
<input type="text" class="form-control" id="c_fname" name="c_fname">
</div>
<div class="col-md-6">
<div
class="col-md-6"
hx-target="this"
hx-swap="outerHTML"
>
<label for="c_lname" class="text-black">Last Name <span class="text-danger">*</span></label>
<label class="text-danger">{{lastNameError}}</label>
<input type="text" class="form-control" id="c_lname" name="c_lname">
<input type="text" class="form-control" id="c_lname"
hx-post="/lname"
name="c_lname"
>
</div>
</div>

25
src/a3pkg/htmx.nim Normal file
View File

@ -0,0 +1,25 @@
import
strformat
type
Validity* = object
message*: string
class*: string
proc sendLastName*(lastName: string, input: Validity): string =
result = fmt"""
<div
class="col-md-6"
hx-target="this"
hx-swap="outerHTML"
>
<label for="c_lname" class="text-black">Last Name <span class="text-danger">*</span></label>
<label class="{input.class}">{input.message}</label>
<input type="text" class="form-control" id="c_lname"
hx-post="lname"
name="c_lname"
value="{lastName}"
>
</div>
"""