feat: Begins reset password view workflow.

This commit is contained in:
2025-01-26 21:19:16 -05:00
parent d4a2048b12
commit 72221a5cb3
3 changed files with 40 additions and 3 deletions

View File

@@ -8,6 +8,11 @@ extension HTMLAttribute.hx {
get(SiteRoute.View.router.path(for: route))
}
@Sendable
static func patch(route: SiteRoute.View) -> HTMLAttribute {
patch(SiteRoute.View.router.path(for: route))
}
@Sendable
static func post(route: SiteRoute.View) -> HTMLAttribute {
post(SiteRoute.View.router.path(for: route))

View File

@@ -9,6 +9,7 @@ struct UserDetail: HTML, Sendable {
let user: User?
var content: some HTML {
// TODO: Need a reset password form.
Float(shouldDisplay: user != nil, resetURL: .user(.index)) {
if let user {
form(
@@ -46,6 +47,10 @@ struct UserDetail: HTML, Sendable {
.toggleContent(.float), .setWindowLocation(to: .user(.index))
)
)
// TODO: trigger the reset password route.
button(
.class("btn-primary")
) { "Reset Password" }
}
}
}

View File

@@ -20,7 +20,7 @@ struct UserForm: HTML, Sendable {
form(
.id(.user(.form)),
.class("user-form"),
.hx.post(route: context.targetURL),
context.isResetPassword ? .hx.patch(route: context.targetURL) : .hx.post(route: context.targetURL),
.hx.pushURL(context.pushURL),
.hx.target(context.target),
.hx.swap(context == .create ? .afterBegin.transition(true).swap("0.5s") : .outerHTML),
@@ -32,8 +32,10 @@ struct UserForm: HTML, Sendable {
if case let .login(next) = context, let next {
input(.type(.hidden), .name("next"), .value(next))
}
div(.class("row")) {
input(.type(.text), .id("username"), .name("username"), .placeholder("Username"), .autofocus, .required)
if context.showUsername {
div(.class("row")) {
input(.type(.text), .id("username"), .name("username"), .placeholder("Username"), .autofocus, .required)
}
}
if context.showEmailInput {
div(.class("row")) {
@@ -61,11 +63,26 @@ struct UserForm: HTML, Sendable {
enum Context: Equatable, Sendable {
case create
case login(next: String?)
case resetPassword(id: User.ID)
var isResetPassword: Bool {
guard case .resetPassword = self else { return false }
return true
}
var showUsername: Bool {
switch self {
case .create: return true
case .login: return true
case .resetPassword: return false
}
}
var showConfirmPassword: Bool {
switch self {
case .create: return true
case .login: return false
case .resetPassword: return true
}
}
@@ -73,6 +90,7 @@ struct UserForm: HTML, Sendable {
switch self {
case .create: return true
case .login: return false
case .resetPassword: return false
}
}
@@ -80,6 +98,7 @@ struct UserForm: HTML, Sendable {
switch self {
case .create: return false
case .login: return true
case .resetPassword: return false
}
}
@@ -89,6 +108,8 @@ struct UserForm: HTML, Sendable {
return "Create"
case .login:
return "Login"
case .resetPassword:
return "Reset"
}
}
@@ -98,6 +119,9 @@ struct UserForm: HTML, Sendable {
return .id(.user(.table))
case .login:
return .body
case .resetPassword:
// FIX: doesn't return anything
return .this
}
}
@@ -107,6 +131,9 @@ struct UserForm: HTML, Sendable {
return .user(.index)
case .login:
return .login(.index())
case .resetPassword:
// FIX: Route.
return .user(.index)
}
}
}