summaryrefslogtreecommitdiff
path: root/internal/tui/modal.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/tui/modal.go')
-rw-r--r--internal/tui/modal.go88
1 files changed, 67 insertions, 21 deletions
diff --git a/internal/tui/modal.go b/internal/tui/modal.go
index 51ac384..248654b 100644
--- a/internal/tui/modal.go
+++ b/internal/tui/modal.go
@@ -19,7 +19,8 @@ type ModalType int
const (
ModalTypeClient ModalType = iota
- ModalTypeProject
+ ModalTypeProjectCreate
+ ModalTypeProjectEdit
ModalTypeDeleteConfirmation
ModalTypeEntry
ModalTypeHistoryFilter
@@ -33,8 +34,10 @@ func (mt ModalType) newForm() Form {
return NewEntryEditorForm()
case ModalTypeClient:
return NewClientForm()
- case ModalTypeProject:
- return NewProjectForm()
+ case ModalTypeProjectCreate:
+ return NewProjectCreateForm()
+ case ModalTypeProjectEdit:
+ return NewProjectEditForm()
case ModalTypeHistoryFilter:
return NewHistoryFilterForm()
case ModalTypeGenerateReport:
@@ -93,7 +96,7 @@ func (m ModalBoxModel) Render() string {
return m.RenderDeleteConfirmation()
case ModalTypeClient:
return m.RenderFormModal("👤 Client")
- case ModalTypeProject:
+ case ModalTypeProjectCreate, ModalTypeProjectEdit:
return m.RenderFormModal("📂 Project")
case ModalTypeHistoryFilter:
return m.RenderFormModal("🔍 History Filter")
@@ -126,7 +129,7 @@ func (m ModalBoxModel) RenderDeleteConfirmation() string {
}
func (m *ModalBoxModel) activateCreateProjectModal(am AppModel) {
- m.activate(ModalTypeProject, 0, am)
+ m.activate(ModalTypeProjectCreate, 0, am)
if am.selectedBox == ProjectsBox && len(am.projectsBox.clients) > 0 {
client := am.projectsBox.clients[am.projectsBox.selectedClient]
m.form.fields[1].SetValue(client.Name)
@@ -152,6 +155,23 @@ func (m *ModalBoxModel) populateContractorFields(contractor ContractorInfo) {
m.form.fields[2].SetValue(contractor.email)
}
+func (m *ModalBoxModel) populateClientFields(client queries.Client) {
+ m.form.fields[0].SetValue(client.Name)
+ if client.Email.Valid {
+ m.form.fields[1].SetValue(client.Email.String)
+ }
+ if client.BillableRate.Valid {
+ m.form.fields[2].SetValue(fmt.Sprintf("%.2f", float64(client.BillableRate.Int64)/100))
+ }
+}
+
+func (m *ModalBoxModel) populateProjectFields(project queries.Project) {
+ m.form.fields[0].SetValue(project.Name)
+ if project.BillableRate.Valid {
+ m.form.fields[2].SetValue(fmt.Sprintf("%.2f", float64(project.BillableRate.Int64)/100))
+ }
+}
+
var (
boldStyle = lipgloss.NewStyle().Bold(true)
modalTitleStyle = boldStyle
@@ -182,8 +202,8 @@ func (m *ModalBoxModel) SubmitForm(am AppModel) tea.Cmd {
return reOpenModal()
}
- msg := am.refreshCmd()
- return func() tea.Msg { return msg }
+ return am.refreshCmd
+
case ModalTypeClient:
if err := m.form.Error(); err != nil {
return reOpenModal()
@@ -196,10 +216,42 @@ func (m *ModalBoxModel) SubmitForm(am AppModel) tea.Cmd {
}
if m.editedID != 0 {
- panic("editing a client not yet implemented")
+ if _, err := actions.New(am.queries).EditClient(
+ context.Background(),
+ m.editedID,
+ m.form.fields[0].Value(),
+ m.form.fields[1].Value(),
+ rate,
+ ); err != nil {
+ m.form.err = err
+ return reOpenModal()
+ }
+ } else {
+ if _, err := actions.New(am.queries).CreateClient(
+ context.Background(),
+ m.form.fields[0].Value(),
+ m.form.fields[1].Value(),
+ rate,
+ ); err != nil {
+ m.form.err = err
+ return reOpenModal()
+ }
}
- if _, err := actions.New(am.queries).CreateClient(
+ return am.refreshCmd
+
+ case ModalTypeProjectCreate:
+ if err := m.form.Error(); err != nil {
+ return reOpenModal()
+ }
+
+ var rate *float64
+ if value := m.form.fields[2].Value(); value != "" {
+ r, _ := strconv.ParseFloat(value, 64)
+ rate = &r
+ }
+
+ if _, err := actions.New(am.queries).CreateProject(
context.Background(),
m.form.fields[0].Value(),
m.form.fields[1].Value(),
@@ -209,36 +261,30 @@ func (m *ModalBoxModel) SubmitForm(am AppModel) tea.Cmd {
return reOpenModal()
}
- msg := am.refreshCmd()
- return func() tea.Msg { return msg }
+ return am.refreshCmd
- case ModalTypeProject:
+ case ModalTypeProjectEdit:
if err := m.form.Error(); err != nil {
return reOpenModal()
}
var rate *float64
- if value := m.form.fields[2].Value(); value != "" {
+ if value := m.form.fields[1].Value(); value != "" {
r, _ := strconv.ParseFloat(value, 64)
rate = &r
}
- if m.editedID != 0 {
- panic("editing a project not yet implemented")
- }
-
- if _, err := actions.New(am.queries).CreateProject(
+ if _, err := actions.New(am.queries).EditProject(
context.Background(),
+ m.editedID,
m.form.fields[0].Value(),
- m.form.fields[1].Value(),
rate,
); err != nil {
m.form.err = err
return reOpenModal()
}
- msg := am.refreshCmd()
- return func() tea.Msg { return msg }
+ return am.refreshCmd
case ModalTypeHistoryFilter:
if err := m.form.Error(); err != nil {