add edit issue button and modal
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/components"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/routes"
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
@@ -49,7 +50,7 @@ func CreateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
issue := form.toIssue()
|
||||
if err := app.Issues.CreateIssue(r.Context(), &issue, ""); err != nil {
|
||||
if err := app.Issues.CreateIssue(r.Context(), &issue, "Me"); err != nil {
|
||||
http.Error(w, "Failed to create issue: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
@@ -170,6 +171,17 @@ func UpdateIssue(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if hx.IsHxRequest() {
|
||||
w.Header().Set("HX-Trigger", `{"closeModal": "edit-issue-modal", "issueUpdated": "`+issue.ID+`"}`)
|
||||
w.Header().Set("HX-Retarget", "#issue-detail-container")
|
||||
w.Header().Set("HX-Reswap", "innerHTML")
|
||||
|
||||
components.IssueDetail(components.IssueDetailProps{
|
||||
Issue: issue,
|
||||
}).Render(r.Context(), w)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
hx.WriteJSON(issue)
|
||||
}
|
||||
|
||||
@@ -3,15 +3,16 @@ package handler
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/web/components"
|
||||
)
|
||||
|
||||
func CreateIssueFormModal(w http.ResponseWriter, r *http.Request) {
|
||||
modalContent := components.IssueForm(components.IssueFormProps{
|
||||
Action: "/issues",
|
||||
Status: "open",
|
||||
IssueType: "task",
|
||||
Priority: 0,
|
||||
PostAction: "/issues",
|
||||
Status: "open",
|
||||
IssueType: "task",
|
||||
Priority: 0,
|
||||
})
|
||||
|
||||
modal := components.Modal(components.ModalProps{
|
||||
@@ -23,3 +24,29 @@ func CreateIssueFormModal(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
modal.Render(r.Context(), w)
|
||||
}
|
||||
|
||||
func EditIssueFormModal(w http.ResponseWriter, r *http.Request) {
|
||||
issue := r.Context().Value(issueKey).(*models.Issue)
|
||||
|
||||
if issue == nil {
|
||||
http.Error(w, "Issue not found in context", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
modalContent := components.IssueForm(components.IssueFormProps{
|
||||
PatchAction: "/issues/" + issue.ID,
|
||||
Title: issue.Title,
|
||||
Description: issue.Description,
|
||||
Status: string(issue.Status),
|
||||
IssueType: string(issue.IssueType),
|
||||
Priority: issue.Priority,
|
||||
})
|
||||
|
||||
modal := components.Modal(components.ModalProps{
|
||||
ID: "edit-issue-modal",
|
||||
Title: "Edit Issue",
|
||||
Content: modalContent,
|
||||
Open: true,
|
||||
})
|
||||
modal.Render(r.Context(), w)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user