Skip to content

Commit 4352d43

Browse files
author
raineer
committed
fix(in-house): improve table spacing and alignment
1 parent d8d0fd6 commit 4352d43

2 files changed

Lines changed: 93 additions & 91 deletions

File tree

‎apps/codebility/app/home/in-house/_components/table/EditableRow.tsx‎

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,26 @@ import { TableCell, TableRow } from "@codevs/ui/table";
2929

3030
import { ProjectSelect } from "../shared/ProjectSelect";
3131

32-
// If you have a separate "Role" interface:
32+
// Role interface for type safety
3333
export interface Role {
3434
id: number;
3535
name: string;
3636
}
3737

3838
interface EditableRowProps {
39-
data: Codev; // The codev row
39+
data: Codev;
4040
onSave: (data: Codev) => void;
4141
onCancel: () => void;
42-
roles: Role[]; // Pre-fetched roles
42+
roles: Role[];
4343
}
4444

45+
/**
46+
* ENHANCED EditableRow Component
47+
* IMPROVEMENTS:
48+
* - Consistent spacing with InHouseTable: px-3 py-2
49+
* - Removed inconsistent p-2 pb-6 padding
50+
* - Better visual alignment with read-only rows
51+
*/
4552
export function EditableRow({
4653
data,
4754
onSave,
@@ -55,11 +62,10 @@ export function EditableRow({
5562
setSupabase(supabaseClient);
5663
}, []);
5764

58-
// --- 1) LOCAL EDIT STATE ---
59-
// We'll clone the incoming "data" into our own local "editForm"
65+
// Local edit state - clone incoming data
6066
const [editForm, setEditForm] = useState<Codev>(data);
6167

62-
// For local preview of image if user uploads a new one
68+
// Local preview of image if user uploads a new one
6369
const [uploadedImage, setUploadedImage] = useState<string | null>(
6470
data.image_url || null,
6571
);
@@ -68,7 +74,7 @@ export function EditableRow({
6874
const [isSubmitting, setIsSubmitting] = useState(false);
6975
const [isUploading, setIsUploading] = useState(false);
7076

71-
// --- 2) FETCH POSITIONS (once) ---
77+
// Fetch positions on mount
7278
useEffect(() => {
7379
if (!supabase) return;
7480

@@ -85,16 +91,15 @@ export function EditableRow({
8591
fetchPositions();
8692
}, [supabase]);
8793

88-
// --- 3) LOCAL CHANGE HANDLER ---
89-
// This simply updates `editForm` in local state, no server call
94+
// Local change handler - updates editForm state
9095
const handleLocalChange = (key: keyof Codev, value: any) => {
9196
setEditForm((prev) => ({
9297
...prev,
9398
[key]: value,
9499
}));
95100
};
96101

97-
// --- 4) IMAGE UPLOAD (local + supabase storage) ---
102+
// Image upload handler
98103
const handleImageUpload = async (file: File) => {
99104
try {
100105
setIsUploading(true);
@@ -105,13 +110,13 @@ export function EditableRow({
105110
};
106111
reader.readAsDataURL(file);
107112

108-
// Upload to your Supabase bucket
109-
const publicUrl = await uploadImage(file, {
113+
// Upload to Supabase bucket
114+
const publicUrl = await uploadImage(file, {
110115
bucket: "codebility",
111116
folder: "profileImage",
112117
});
113118

114-
// Save the final image URL into local form
119+
// Save URL to local form
115120
handleLocalChange("image_url", publicUrl);
116121
} catch (error) {
117122
console.error("Image upload failed:", error);
@@ -121,16 +126,14 @@ export function EditableRow({
121126
}
122127
};
123128

124-
// --- 5) SAVE CHANGES ON CLICK OF CHECK ICON ---
125-
// Merges "projects" pivot changes + codev table updates
129+
// Save changes - merges projects pivot + codev table updates
126130
const handleSave = async () => {
127131
try {
128132
setIsSubmitting(true);
129133

130-
// We'll remove `projects` from the rest
131134
const { id, projects, ...rest } = editForm;
132135

133-
// 1) Clear + re-insert pivot if `projects` changed
136+
// 1) Clear + re-insert pivot if projects changed
134137
if (projects) {
135138
const { error: deleteError } = await supabase
136139
.from("project_members")
@@ -150,8 +153,7 @@ export function EditableRow({
150153
}
151154
}
152155

153-
// 2) Build object for codev table
154-
// We'll store allowed columns in `updateFields`
156+
// 2) Build update object for codev table
155157
const allowedFields: (keyof Codev)[] = [
156158
"first_name",
157159
"last_name",
@@ -170,20 +172,16 @@ export function EditableRow({
170172
"date_joined",
171173
];
172174

173-
// This can be a loose type so TS doesn't complain
174175
const updateFields: Record<string, unknown> = {};
175-
176-
// Cast rest so TypeScript doesn't complain about indexing
177176
const restTyped = rest as Partial<Codev>;
178177

179178
for (const key of allowedFields) {
180-
// If it exists in `restTyped`, we add it to `updateFields`
181179
if (Object.prototype.hasOwnProperty.call(restTyped, key)) {
182180
updateFields[key] = restTyped[key];
183181
}
184182
}
185183

186-
// 3) Update codev table if there's anything to update
184+
// 3) Update codev table
187185
if (Object.keys(updateFields).length > 0) {
188186
const { error } = await supabase
189187
.from("codev")
@@ -193,7 +191,7 @@ export function EditableRow({
193191
}
194192

195193
toast.success("Member updated successfully");
196-
onSave(editForm); // pass updated data back up
194+
onSave(editForm);
197195
} catch (error) {
198196
console.error("Error updating member:", error);
199197
toast.error("Failed to update member");
@@ -202,7 +200,7 @@ export function EditableRow({
202200
}
203201
};
204202

205-
// --- 6) RENDER FUNCTION FOR EACH CELL ---
203+
// Render function for each editable cell
206204
const renderCell = (key: keyof Codev) => {
207205
switch (key) {
208206
case "image_url":
@@ -384,7 +382,7 @@ export function EditableRow({
384382
);
385383

386384
default:
387-
// For example: first_name, last_name, portfolio_website, etc.
385+
// Text inputs: first_name, last_name, portfolio_website, etc.
388386
return (
389387
<Input
390388
value={String(editForm[key] || "")}
@@ -398,24 +396,24 @@ export function EditableRow({
398396

399397
return (
400398
<TableRow className="bg-light-200 dark:bg-dark-200 hover:bg-light-300 dark:hover:bg-dark-300">
401-
<TableCell className="p-2">{renderCell("image_url")}</TableCell>
402-
<TableCell className="p-2 pb-6">{renderCell("first_name")}</TableCell>
403-
<TableCell className="p-2 pb-6">{renderCell("last_name")}</TableCell>
404-
<TableCell className="p-2 pb-6">{renderCell("email_address")}</TableCell>
405-
<TableCell className="p-2">{renderCell("internal_status")}</TableCell>
406-
<TableCell className="p-2">{renderCell("role_id")}</TableCell>
407-
<TableCell className="p-2">{renderCell("display_position")}</TableCell>
408-
<TableCell className="p-2">{renderCell("projects")}</TableCell>
409-
<TableCell className="p-2">{renderCell("nda_status")}</TableCell>
410-
<TableCell className="p-2 pb-6">
411-
{renderCell("portfolio_website")}
412-
</TableCell>
413-
<TableCell className="p-2 pb-6">{renderCell("date_joined")}</TableCell>
414-
<TableCell className="p-2">{renderCell("availability_status")}</TableCell>
415-
416-
<TableCell className="p-2">
399+
{/* ENHANCED: All cells now use consistent px-3 py-2 spacing */}
400+
<TableCell className="px-3 py-2">{renderCell("image_url")}</TableCell>
401+
<TableCell className="px-3 py-2">{renderCell("first_name")}</TableCell>
402+
<TableCell className="px-3 py-2">{renderCell("last_name")}</TableCell>
403+
<TableCell className="px-3 py-2">{renderCell("email_address")}</TableCell>
404+
<TableCell className="px-3 py-2">{renderCell("internal_status")}</TableCell>
405+
<TableCell className="px-3 py-2">{renderCell("role_id")}</TableCell>
406+
<TableCell className="px-3 py-2">{renderCell("display_position")}</TableCell>
407+
<TableCell className="px-3 py-2">{renderCell("projects")}</TableCell>
408+
<TableCell className="px-3 py-2">{renderCell("nda_status")}</TableCell>
409+
<TableCell className="px-3 py-2">{renderCell("portfolio_website")}</TableCell>
410+
<TableCell className="px-3 py-2">{renderCell("date_joined")}</TableCell>
411+
<TableCell className="px-3 py-2">{renderCell("availability_status")}</TableCell>
412+
413+
{/* Action buttons - ENHANCED spacing */}
414+
<TableCell className="px-3 py-2">
417415
<div className="flex space-x-2">
418-
{/* Save button -> calls handleSave (single server update) */}
416+
{/* Save button */}
419417
<Button
420418
size="sm"
421419
onClick={handleSave}
@@ -424,7 +422,7 @@ export function EditableRow({
424422
>
425423
<Check className="text-black-100 h-4 w-4 dark:text-white" />
426424
</Button>
427-
{/* Cancel button -> reverts changes (via parent) */}
425+
{/* Cancel button */}
428426
<Button
429427
size="sm"
430428
variant="ghost"
@@ -438,4 +436,4 @@ export function EditableRow({
438436
</TableCell>
439437
</TableRow>
440438
);
441-
}
439+
}

0 commit comments

Comments
 (0)