File size: 5,402 Bytes
4d6acfa
 
 
6c34734
4d6acfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225139b
4d6acfa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225139b
 
 
 
 
 
 
 
 
 
 
 
 
4d6acfa
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { useState, type FormEvent, type ReactNode } from "react";

import { Drawer } from "../ui/Drawer";
import type { ProjectInput, Team } from "../../types";

const PROJECT_COLORS = ["#0ea5e9", "#16a34a", "#f97316", "#a855f7", "#facc15", "#ef4444", "#0f766e"];

const LIFECYCLE_STATUSES = [
  { value: "planning", label: "Planning" },
  { value: "active", label: "Active" },
  { value: "on_hold", label: "On hold" },
  { value: "completed", label: "Completed" },
] as const;

interface ProjectDrawerProps {
  open: boolean;
  editingId: number | null;
  form: ProjectInput;
  setForm: (next: ProjectInput) => void;
  teams: Team[];
  onClose: () => void;
  onSubmit: (event: FormEvent<HTMLFormElement>) => void;
  isSaving: boolean;
  footerExtras?: ReactNode;
}

export function ProjectDrawer({
  open,
  editingId,
  form,
  setForm,
  teams,
  onClose,
  onSubmit,
  isSaving,
  footerExtras,
}: ProjectDrawerProps) {
  const [tab, setTab] = useState<"details" | "notes">("details");
  const title = editingId ? `Edit ${form.name || "project"}` : "New project";

  return (
    <Drawer
      open={open}
      onClose={onClose}
      title={title}
      icon={<span className="project-swatch drawer-project-swatch" style={{ background: form.color }} />}
      tabs={
        <>
          <button
            className={`drawer-tab ${tab === "details" ? "active" : ""}`}
            onClick={() => setTab("details")}
            type="button"
          >
            Details
          </button>
          <button
            className={`drawer-tab ${tab === "notes" ? "active" : ""}`}
            onClick={() => setTab("notes")}
            type="button"
          >
            Notes
          </button>
        </>
      }
      footer={
        <>
          {footerExtras}
          <span className="drawer-footer-spacer" />
          <button className="secondary-button" onClick={onClose} type="button">
            Cancel
          </button>
          <button className="primary-button" disabled={isSaving} form="project-drawer-form" type="submit">
            Save
          </button>
        </>
      }
    >
      <form className="drawer-form" id="project-drawer-form" onSubmit={onSubmit}>
        {tab === "details" ? (
          <>
            <label>
              Project Name
              <input
                onChange={(event) => setForm({ ...form, name: event.target.value })}
                required
                type="text"
                value={form.name}
              />
            </label>
            <label>
              Status
              <select
                onChange={(event) => setForm({ ...form, is_tentative: event.target.value === "tentative" })}
                value={form.is_tentative ? "tentative" : "confirmed"}
              >
                <option value="confirmed">Confirmed</option>
                <option value="tentative">Tentative</option>
              </select>
            </label>
            <label>
              Primary Team <small>(optional)</small>
              <select
                onChange={(event) =>
                  setForm({ ...form, team_id: event.target.value ? Number(event.target.value) : null })
                }
                value={form.team_id ?? ""}
              >
                <option value="">No team</option>
                {teams.map((team) => (
                  <option key={team.id} value={team.id}>
                    {team.name}
                  </option>
                ))}
              </select>
            </label>
            <label>
              Lifecycle <small>(internal)</small>
              <select onChange={(event) => setForm({ ...form, status: event.target.value })} value={form.status}>
                {LIFECYCLE_STATUSES.map((status) => (
                  <option key={status.value} value={status.value}>
                    {status.label}
                  </option>
                ))}
              </select>
            </label>
            <label>
              Project type
              <select onChange={(event) => setForm({ ...form, type: event.target.value })} value={form.type}>
                <option value="infrastructure">Infrastructure</option>
                <option value="development">Development</option>
                <option value="support">Support</option>
                <option value="other">Other</option>
              </select>
            </label>
            <label>
              Color
              <div className="color-picker">
                {PROJECT_COLORS.map((color) => (
                  <button
                    aria-label={`Use color ${color}`}
                    className={`color-swatch ${form.color === color ? "selected" : ""}`}
                    key={color}
                    onClick={() => setForm({ ...form, color })}
                    style={{ background: color }}
                    type="button"
                  />
                ))}
              </div>
            </label>
          </>
        ) : null}

        {tab === "notes" ? (
          <label>
            Notes
            <textarea
              onChange={(event) => setForm({ ...form, description: event.target.value })}
              placeholder="Project notes and context"
              rows={8}
              value={form.description ?? ""}
            />
          </label>
        ) : null}

      </form>
    </Drawer>
  );
}