feat: Begins reset password view workflow.
This commit is contained in:
@@ -8,6 +8,11 @@ extension HTMLAttribute.hx {
|
|||||||
get(SiteRoute.View.router.path(for: route))
|
get(SiteRoute.View.router.path(for: route))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Sendable
|
||||||
|
static func patch(route: SiteRoute.View) -> HTMLAttribute {
|
||||||
|
patch(SiteRoute.View.router.path(for: route))
|
||||||
|
}
|
||||||
|
|
||||||
@Sendable
|
@Sendable
|
||||||
static func post(route: SiteRoute.View) -> HTMLAttribute {
|
static func post(route: SiteRoute.View) -> HTMLAttribute {
|
||||||
post(SiteRoute.View.router.path(for: route))
|
post(SiteRoute.View.router.path(for: route))
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ struct UserDetail: HTML, Sendable {
|
|||||||
let user: User?
|
let user: User?
|
||||||
|
|
||||||
var content: some HTML {
|
var content: some HTML {
|
||||||
|
// TODO: Need a reset password form.
|
||||||
Float(shouldDisplay: user != nil, resetURL: .user(.index)) {
|
Float(shouldDisplay: user != nil, resetURL: .user(.index)) {
|
||||||
if let user {
|
if let user {
|
||||||
form(
|
form(
|
||||||
@@ -46,6 +47,10 @@ struct UserDetail: HTML, Sendable {
|
|||||||
.toggleContent(.float), .setWindowLocation(to: .user(.index))
|
.toggleContent(.float), .setWindowLocation(to: .user(.index))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
// TODO: trigger the reset password route.
|
||||||
|
button(
|
||||||
|
.class("btn-primary")
|
||||||
|
) { "Reset Password" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ struct UserForm: HTML, Sendable {
|
|||||||
form(
|
form(
|
||||||
.id(.user(.form)),
|
.id(.user(.form)),
|
||||||
.class("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.pushURL(context.pushURL),
|
||||||
.hx.target(context.target),
|
.hx.target(context.target),
|
||||||
.hx.swap(context == .create ? .afterBegin.transition(true).swap("0.5s") : .outerHTML),
|
.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 {
|
if case let .login(next) = context, let next {
|
||||||
input(.type(.hidden), .name("next"), .value(next))
|
input(.type(.hidden), .name("next"), .value(next))
|
||||||
}
|
}
|
||||||
div(.class("row")) {
|
if context.showUsername {
|
||||||
input(.type(.text), .id("username"), .name("username"), .placeholder("Username"), .autofocus, .required)
|
div(.class("row")) {
|
||||||
|
input(.type(.text), .id("username"), .name("username"), .placeholder("Username"), .autofocus, .required)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if context.showEmailInput {
|
if context.showEmailInput {
|
||||||
div(.class("row")) {
|
div(.class("row")) {
|
||||||
@@ -61,11 +63,26 @@ struct UserForm: HTML, Sendable {
|
|||||||
enum Context: Equatable, Sendable {
|
enum Context: Equatable, Sendable {
|
||||||
case create
|
case create
|
||||||
case login(next: String?)
|
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 {
|
var showConfirmPassword: Bool {
|
||||||
switch self {
|
switch self {
|
||||||
case .create: return true
|
case .create: return true
|
||||||
case .login: return false
|
case .login: return false
|
||||||
|
case .resetPassword: return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +90,7 @@ struct UserForm: HTML, Sendable {
|
|||||||
switch self {
|
switch self {
|
||||||
case .create: return true
|
case .create: return true
|
||||||
case .login: return false
|
case .login: return false
|
||||||
|
case .resetPassword: return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +98,7 @@ struct UserForm: HTML, Sendable {
|
|||||||
switch self {
|
switch self {
|
||||||
case .create: return false
|
case .create: return false
|
||||||
case .login: return true
|
case .login: return true
|
||||||
|
case .resetPassword: return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,6 +108,8 @@ struct UserForm: HTML, Sendable {
|
|||||||
return "Create"
|
return "Create"
|
||||||
case .login:
|
case .login:
|
||||||
return "Login"
|
return "Login"
|
||||||
|
case .resetPassword:
|
||||||
|
return "Reset"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +119,9 @@ struct UserForm: HTML, Sendable {
|
|||||||
return .id(.user(.table))
|
return .id(.user(.table))
|
||||||
case .login:
|
case .login:
|
||||||
return .body
|
return .body
|
||||||
|
case .resetPassword:
|
||||||
|
// FIX: doesn't return anything
|
||||||
|
return .this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +131,9 @@ struct UserForm: HTML, Sendable {
|
|||||||
return .user(.index)
|
return .user(.index)
|
||||||
case .login:
|
case .login:
|
||||||
return .login(.index())
|
return .login(.index())
|
||||||
|
case .resetPassword:
|
||||||
|
// FIX: Route.
|
||||||
|
return .user(.index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user