Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | 3x 3x 3x 3x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 987x 79x 79x 52x 52x 52x 987x 7x 7x 987x 72x 72x 987x 987x 987x 74x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 987x 8x 8x 987x 161x 1x 1x 1x 1x 987x 30x 30x 29x 29x 1x 1x 987x 54x 50x 987x 31x 1x 1x 30x 1x 1x 29x 29x 29x 29x 29x 29x 29x 1x 28x 28x 28x 28x 2x 28x 1x 1x 29x 987x 32x 32x 32x 1x 31x 31x 31x 31x 31x 31x 30x 30x 30x 30x 30x 30x 30x 1x 31x 1x 31x 31x 987x 2x 2x 1x 1x 1x 1x 1x 1x 1x 987x 2x 2x 2x 987x 1x 1x 1x 987x 32x 32x 32x 32x 32x 32x 1x 1x 31x 31x 30x 30x 987x 2x 2x 2x 2x 2x 1x 1x 1x 987x 83x 83x 60x 60x 3x 3x 57x 57x 57x 56x 55x 56x 55x 55x 1x 56x 23x 21x 21x 21x 21x 21x 21x 21x 21x 23x 21x 2x 2x 2x 2x 1x 987x 6x 6x 6x 6x 987x 5x 2x 2x 2x 3x 3x 987x 983x 987x 960x 783x 177x 987x 983x 177x 806x 987x 987x 987x 706x 706x 1x 36x 354x 9x 2x 2x 27x 2x 25x 987x 2x 981x | import { useState, useEffect, useRef, type ChangeEvent } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { ArrowLeft, X, Upload, Plus, Check, Camera } from "lucide-react";
import {
validateProjectTitle,
projectTitleErrorMessage,
normalizeProjectTitle,
} from "@interioring/utils/validation/project-title";
import { notify } from "../../lib/notify";
import { Button } from "../ui/button";
import { Input } from "../ui/input";
import { OnboardingProgress } from "../onboarding/OnboardingProgress";
import { useDialogAccessibility } from "../../hooks";
import { useIsMobile } from "../../hooks/useIsMobile";
import {
proApi,
ApiError,
getErrorMessage,
getImageUrl,
type Media,
type Project,
} from "../../lib/api";
import { queryKeys } from "../../lib/query-keys";
import {
useCreateProject,
useUpdateProject,
} from "../../hooks/mutations/useProjectMutations";
import { useRoomTypes } from "../../hooks/queries/useTaxonomyQueries";
import { BasicInfoSection } from "./form-sections";
import { API_BASE_URL } from "../../lib/api/base";
interface ProjectCreationWizardProps {
isOpen: boolean;
onClose: () => void;
onComplete: (projectId: string) => void;
proId: string;
}
interface RoomState {
roomType: string;
name: string;
areaSqft: string;
styleTags: string[];
budgetSpent: string;
materials: string[];
roomId?: number;
photoCount: number;
}
const STEP_TITLES = [
"Project Info",
"Add Room & Photos",
"Room Summary",
];
const TOTAL_STEPS = 3;
// Allowed image types and size limit
const ALLOWED_IMAGE_TYPES = [
"image/jpeg",
"image/png",
"image/webp",
"image/gif",
"image/avif",
];
const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
export function ProjectCreationWizard({
isOpen,
onClose,
onComplete,
proId,
}: ProjectCreationWizardProps) {
const queryClient = useQueryClient();
// Step navigation
const [currentStep, setCurrentStep] = useState(1);
const [createdProjectId, setCreatedProjectId] = useState<string | null>(null);
// Tracks whether the user completed the wizard via Finish. When the wizard
// is closed before completion, we delete the auto-created project so we
// don't leave empty / image-less projects sitting in the Pro's list
// (regression #585).
const finishedRef = useRef(false);
// Mirrors createdProjectId so the close handler can read the latest value
// without waiting for a state-driven re-render.
const createdProjectIdRef = useRef<string | null>(null);
// Prevent concurrent room creation — stores the pending creation promise.
// Declared up-front so the close-reset effect can clear it.
const pendingRoomCreationRef = useRef<Promise<number | null> | null>(null);
// Step 1 - Basic Info
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
const [titleErrorMessage, setTitleErrorMessage] = useState<string | null>(
null,
);
// Rooms tracking (Steps 4-6)
const [rooms, setRooms] = useState<RoomState[]>([]);
const [currentRoomIndex, setCurrentRoomIndex] = useState(0);
// Current room being edited (Step 2)
const [roomType, setRoomType] = useState("");
const [roomName, setRoomName] = useState("");
// Step 5 - Room Photos
const [isDragOver, setIsDragOver] = useState(false);
const [isUploading, setIsUploading] = useState(false);
const [roomMedia, setRoomMedia] = useState<Media[]>([]);
const fileInputRef = useRef<HTMLInputElement>(null);
// Taxonomy data (cached via React Query)
const { data: roomTypes = [] } = useRoomTypes();
// Mutations
const createProjectMutation = useCreateProject(proId);
const updateProjectMutation = useUpdateProject(
proId,
createdProjectId || "",
);
const isSubmitting =
createProjectMutation.isPending ||
updateProjectMutation.isPending ||
isUploading;
// Discard the auto-created draft project when the user closes the wizard
// before clicking Finish. Best-effort: a network failure here shouldn't
// block the close, so we swallow the error (the user can still delete the
// project from the list).
const discardPendingDraft = () => {
const pendingProjectId = createdProjectIdRef.current;
if (pendingProjectId && !finishedRef.current) {
// Clear the ref immediately so a follow-up call (e.g. unmount fires
// right after handleClose) doesn't issue a duplicate DELETE.
createdProjectIdRef.current = null;
void proApi
.deleteProject(proId, pendingProjectId)
.catch(() => {})
.finally(() => {
queryClient.invalidateQueries({
queryKey: queryKeys.projects.list(proId),
});
});
}
};
const handleClose = () => {
discardPendingDraft();
onClose();
};
// Belt-and-suspenders: if the wizard unmounts without an explicit close
// (e.g. user navigates away via TanStack Router), still clean up the
// orphaned draft. Same root issue as #585.
// biome-ignore lint/correctness/useExhaustiveDependencies: cleanup on unmount only
useEffect(() => {
return () => {
discardPendingDraft();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
// Accessibility
const { dialogRef, handleFocusTrap } = useDialogAccessibility(handleClose);
const isMobile = useIsMobile();
// Reset all form state when modal opens/closes
// biome-ignore lint/correctness/useExhaustiveDependencies: reset on open/close only
useEffect(() => {
if (!isOpen) {
setCurrentStep(1);
setCreatedProjectId(null);
createdProjectIdRef.current = null;
finishedRef.current = false;
pendingRoomCreationRef.current = null;
setTitle("");
setDescription("");
setTitleErrorMessage(null);
setRooms([]);
setCurrentRoomIndex(0);
resetRoomForm();
setRoomMedia([]);
setIsDragOver(false);
setIsUploading(false);
}
}, [isOpen]);
const resetRoomForm = () => {
setRoomType("");
setRoomName("");
};
// Re-populate room form when navigating back to step 2
// biome-ignore lint/correctness/useExhaustiveDependencies: only re-populate on step/index change
useEffect(() => {
if (currentStep === 2 && rooms[currentRoomIndex]?.roomId) {
const room = rooms[currentRoomIndex];
setRoomType(room.roomType);
setRoomName(room.name || "");
// Load existing media for this room
loadRoomMedia(rooms[currentRoomIndex].roomId as number);
}
}, [currentStep, currentRoomIndex]);
// Load media for current room (Step 5)
const loadRoomMedia = async (roomId: number) => {
try {
const response = await proApi.getMediaByRoom(proId, roomId);
Eif (response.data) {
setRoomMedia(response.data);
}
} catch (err) {
console.error("Failed to load room media:", err);
notify.error("Failed to load room photos. Please try again.");
}
};
// Get room type display name
const getRoomTypeName = (code: string) => {
const rt = roomTypes.find((t) => t.code === code);
return rt?.displayName || code;
};
// Photo upload helpers for room media
const handleUploadFile = async (file: File, roomId: number) => {
if (!ALLOWED_IMAGE_TYPES.includes(file.type)) {
notify.error(
"Invalid file type. Please upload JPEG, PNG, WebP, GIF, or AVIF images.",
);
return;
}
if (file.size > MAX_FILE_SIZE) {
notify.error("File too large. Maximum size is 10MB.");
return;
}
setIsUploading(true);
try {
const formData = new FormData();
formData.append("file", file);
const response = await fetch(
`${API_BASE_URL}/api/pro/${proId}/rooms/${roomId}/upload-media`,
{
method: "POST",
credentials: "include",
body: formData,
},
);
const data = await response.json();
if (!response.ok || !data.success) {
throw new ApiError(
data.error?.code || "UPLOAD_ERROR",
data.error?.message || "Failed to upload media",
response.status,
);
}
// Optimistically update project cover in cache if this media became the cover
const uploadedMedia = data.data;
Eif (uploadedMedia?.isCover && uploadedMedia.storageKey && createdProjectId) {
queryClient.setQueryData<Project[]>(
queryKeys.projects.list(proId),
(old) =>
old?.map((p) =>
p.id === createdProjectId
? { ...p, coverImage: uploadedMedia.storageKey }
: p,
),
);
}
// Reload media
await loadRoomMedia(roomId);
} catch (err) {
console.error("Failed to upload media:", err);
notify.error(getErrorMessage(err));
} finally {
setIsUploading(false);
}
};
// Ensure room exists before uploading photos (auto-create if needed)
const ensureRoomExists = async (): Promise<number | null> => {
const existingRoom = rooms[currentRoomIndex];
Iif (existingRoom?.roomId) return existingRoom.roomId;
// If a creation is already in progress, await the same promise
if (pendingRoomCreationRef.current) {
return pendingRoomCreationRef.current;
}
// Auto-create room when first photo is uploaded
Iif (!createdProjectId || !roomType) {
if (!roomType) {
notify.error(
"Please select a Room/Area Type before uploading photos.",
);
}
return null;
}
const creationPromise = (async (): Promise<number | null> => {
try {
const roomData: { roomType: string; name?: string } = { roomType };
Iif (roomName) roomData.name = roomName;
const response = await proApi.createRoom(proId, createdProjectId, roomData);
const createdRoom = response.data;
Eif (createdRoom) {
const newRoom: RoomState = {
roomType,
name: roomName,
areaSqft: "",
styleTags: [],
budgetSpent: "",
materials: [],
roomId: createdRoom.id,
photoCount: 0,
};
setRooms((prev) => {
setCurrentRoomIndex(prev.length === 0 ? 0 : prev.length);
return prev.length === 0 ? [newRoom] : [...prev, newRoom];
});
return createdRoom.id;
}
} catch (err) {
notify.error(getErrorMessage(err));
} finally {
pendingRoomCreationRef.current = null;
}
return null;
})();
pendingRoomCreationRef.current = creationPromise;
return creationPromise;
};
const handleFileSelect = async (e: ChangeEvent<HTMLInputElement>) => {
const files = e.target.files;
if (!files || files.length === 0) return;
Iif (!roomType) {
notify.error(
"Please select a Room/Area Type before uploading photos.",
);
e.target.value = "";
return;
}
const roomId = await ensureRoomExists();
Iif (!roomId) return;
for (let i = 0; i < files.length; i++) {
await handleUploadFile(files[i], roomId);
}
Eif (fileInputRef.current) {
fileInputRef.current.value = "";
}
};
const handleDragOver = (e: React.DragEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
setIsDragOver(true);
};
const handleDragLeave = (e: React.DragEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
setIsDragOver(false);
};
const handleDrop = async (e: React.DragEvent<HTMLElement>) => {
e.preventDefault();
e.stopPropagation();
setIsDragOver(false);
const files = e.dataTransfer.files;
Iif (files.length === 0) return;
if (!roomType) {
notify.error(
"Please select a Room/Area Type before uploading photos.",
);
return;
}
const roomId = await ensureRoomExists();
if (!roomId) return;
for (let i = 0; i < files.length; i++) {
await handleUploadFile(files[i], roomId);
}
};
const handleSetCover = async (mediaId: number) => {
const currentRoom = rooms[currentRoomIndex];
const roomId = currentRoom?.roomId;
Iif (!roomId) return;
try {
await proApi.setRoomCover(proId, roomId, mediaId);
await loadRoomMedia(roomId);
notify.success("Cover photo set");
} catch (err) {
notify.error(getErrorMessage(err));
}
};
// Navigation logic
const handleNext = async () => {
try {
if (currentStep === 1) {
const titleError = validateProjectTitle(title);
if (titleError) {
setTitleErrorMessage(projectTitleErrorMessage(titleError));
return;
}
const normalizedTitle = normalizeProjectTitle(title);
// Create project (or reuse if already created from a failed attempt)
let projectId = createdProjectId;
if (!projectId) {
const result = await createProjectMutation.mutateAsync({
title: normalizedTitle,
description: description || null,
useRooms: true,
});
projectId = result?.id || null;
if (projectId) {
setCreatedProjectId(projectId);
createdProjectIdRef.current = projectId;
}
} else {
// Project exists from prior attempt — just update title/description
await proApi.updateProject(proId, projectId, {
title: normalizedTitle,
description: description || null,
useRooms: true,
});
}
setCurrentStep(2);
} else if (currentStep === 2) {
// Create or update room, then save photo count and go to summary
Iif (!createdProjectId) return;
const roomData: { roomType: string; name?: string } = { roomType };
Iif (roomName) roomData.name = roomName;
const existingRoom = rooms[currentRoomIndex];
if (existingRoom?.roomId) {
// Update existing room (user navigated back)
await proApi.updateRoom(proId, existingRoom.roomId, roomData);
setRooms((prev) =>
prev.map((r, i) =>
i === currentRoomIndex
? { ...r, roomType, name: roomName, photoCount: roomMedia.length }
: r,
),
);
} else E{
// Create new room
const response = await proApi.createRoom(proId, createdProjectId, roomData);
const createdRoom = response.data;
if (createdRoom) {
const newRoom: RoomState = {
roomType,
name: roomName,
areaSqft: "",
styleTags: [],
budgetSpent: "",
materials: [],
roomId: createdRoom.id,
photoCount: roomMedia.length,
};
setRooms((prev) => {
setCurrentRoomIndex(prev.length === 0 ? 0 : prev.length);
return prev.length === 0 ? [newRoom] : [...prev, newRoom];
});
}
}
setCurrentStep(3);
E} else if (currentStep === 3) {
// Finish — navigate to project detail
Eif (createdProjectId) {
finishedRef.current = true;
onComplete(createdProjectId);
}
}
} catch (err) {
notify.error(getErrorMessage(err));
}
};
const handleAddAnotherRoom = () => {
resetRoomForm();
setRoomMedia([]);
setCurrentRoomIndex(rooms.length);
setCurrentStep(2);
};
const handleBack = () => {
if (currentStep === 2 && rooms.length > 0) {
// Going back from room setup when rooms exist — sync photo count
// from the live roomMedia state before returning to summary
const existingRoom = rooms[currentRoomIndex];
Iif (existingRoom?.roomId) {
setRooms((prev) =>
prev.map((r, i) =>
i === currentRoomIndex
? { ...r, photoCount: roomMedia.length }
: r,
),
);
}
setCurrentStep(3);
E} else if (currentStep > 1) {
setCurrentStep(currentStep - 1);
}
};
if (!isOpen) return null;
// Step 1 button stays enabled once anything is typed so handleNext can
// validate and surface a specific error message (e.g. for "======").
// A fully-empty title still disables the button, matching the prior UX.
const isNextDisabled =
(currentStep === 1 && !title.trim()) ||
(currentStep === 2 && (!roomType || roomMedia.length === 0)) ||
isSubmitting;
// Button labels
const getNextButtonLabel = () => {
switch (currentStep) {
case 1:
return "Create & Continue";
case 2:
return "Save Room";
case 3:
return "Finish";
default:
return "Next";
}
};
// Step title
const getStepTitle = () => {
if (currentStep === 2) {
return rooms.length === 0
? "Add Room & Photos"
: "Add Another Room";
}
return STEP_TITLES[currentStep - 1];
};
// ─── Shared UI pieces ───────────────────────────────────────────────
const progressHeader = (
<>
<OnboardingProgress
currentStep={currentStep}
totalSteps={TOTAL_STEPS}
/>
<p className="text-sm text-foreground-muted mt-2">
Step {currentStep}: {getStepTitle()}
</p>
</>
);
const footerContent = (
<div className="flex items-center gap-3">
{currentStep > 1 && (
<Button
type="button"
variant="outline"
onClick={handleBack}
disabled={isSubmitting}
>
Back
</Button>
)}
<div className="flex-1" />
{currentStep !== 3 && (
<Button
type="button"
onClick={handleNext}
isLoading={isSubmitting}
disabled={isNextDisabled}
>
{getNextButtonLabel()}
</Button>
)}
{currentStep === 3 && (
<Button
type="button"
onClick={handleNext}
isLoading={isSubmitting}
disabled={rooms.length === 0}
>
Finish
</Button>
)}
</div>
);
const stepContent = (
<>
{/* Step 1: Project Info */}
{currentStep === 1 && (
<div className="space-y-1">
<BasicInfoSection
title={title}
description={description}
onTitleChange={(v) => {
setTitle(v);
if (titleErrorMessage && validateProjectTitle(v) === null) {
setTitleErrorMessage(null);
}
}}
onDescriptionChange={setDescription}
titleError={titleErrorMessage}
/>
</div>
)}
{/* Step 2: Add Room + Photos (merged) */}
{currentStep === 2 && (
<div className="space-y-4">
{/* Room Type (required) */}
<div>
<label
htmlFor="room-type"
className="block text-sm font-medium text-foreground-default mb-1"
>
Room/Area Type <span className="text-error">*</span>
</label>
<select
id="room-type"
value={roomType}
onChange={(e) => setRoomType(e.target.value)}
className="flex h-10 w-full rounded-md border border-default bg-background-elevated px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary-500/40 focus:border-primary-500"
>
<option value="">Select room type</option>
{roomTypes.map((rt) => (
<option key={rt.code} value={rt.code}>
{rt.displayName}
</option>
))}
</select>
</div>
{/* Room Name (optional) */}
<div>
<label
htmlFor="room-name"
className="block text-sm font-medium text-foreground-default mb-1"
>
Room Name{" "}
<span className="text-foreground-muted font-normal">
(optional)
</span>
</label>
<Input
id="room-name"
value={roomName}
onChange={(e) => setRoomName(e.target.value)}
placeholder="e.g., Master Bedroom, Kids Room"
/>
</div>
{/* Photos (required) */}
<p className="text-sm font-medium text-foreground-default mb-1">
Photos <span className="text-error">*</span>
</p>
{!roomType && (
<p className="text-xs text-foreground-muted mb-2">
Select a Room/Area Type above to enable photo upload.
</p>
)}
{/* Upload Zone */}
<label
aria-disabled={!roomType || isUploading}
className={`block border-2 border-dashed rounded-lg transition-colors ${
!roomType
? "border-border-default bg-background-muted/40 opacity-60 cursor-not-allowed"
: isDragOver
? "border-primary-500 bg-primary-50 cursor-pointer"
: "border-border-default hover:border-primary-400 hover:bg-background-muted cursor-pointer"
}`}
onDragOver={(e) => {
Iif (!roomType || isUploading) {
e.preventDefault();
e.stopPropagation();
return;
}
handleDragOver(e);
}}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
>
<input
type="file"
ref={fileInputRef}
onChange={handleFileSelect}
accept="image/jpeg,image/png,image/webp,image/gif,image/avif"
multiple
className="sr-only"
disabled={!roomType || isUploading}
/>
<div className="p-4 flex flex-col sm:flex-row sm:items-center gap-3 sm:gap-4">
<div className="flex items-center gap-3 sm:gap-4">
<div
className={`w-10 h-10 sm:w-12 sm:h-12 rounded-lg flex items-center justify-center flex-shrink-0 ${
isDragOver
? "bg-primary-100"
: "bg-background-muted"
}`}
>
{isUploading ? (
<div className="animate-spin rounded-full h-5 w-5 sm:h-6 sm:w-6 border-b-2 border-primary-600" />
) : (
<Upload
className={`h-5 w-5 sm:h-6 sm:w-6 ${
isDragOver
? "text-primary-500"
: "text-foreground-subtle"
}`}
/>
)}
</div>
<div className="flex-1 min-w-0">
{isUploading ? (
<p className="text-sm font-medium text-primary-600">
Uploading...
</p>
) : (
<>
<p
className={`text-sm font-medium ${
isDragOver
? "text-primary-600"
: "text-foreground-default"
}`}
>
{isDragOver
? "Drop images here"
: "Tap to upload or drag and drop"}
</p>
<p className="text-xs text-foreground-muted">
PNG, JPG, WebP, GIF (max 10MB)
</p>
</>
)}
</div>
</div>
</div>
</label>
{/* Uploaded Photos Grid */}
{roomMedia.length === 0 ? (
<div className="text-center py-8 border border-border-default rounded-lg bg-background-muted">
<Camera className="h-8 w-8 text-foreground-subtle mx-auto mb-2" />
<p className="text-foreground-muted text-sm">
No photos yet. Upload photos above to showcase this room.
</p>
</div>
) : (
<div>
<div className="flex items-center justify-between mb-3">
<p className="text-xs text-foreground-muted">
{roomMedia.length} photo
{roomMedia.length !== 1 ? "s" : ""}{" "}
added. Click to set as cover.
</p>
</div>
<ul className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2 sm:gap-3 list-none p-0 m-0">
{roomMedia.map((item, index) => (
<li
key={item.id}
className="relative rounded-lg"
>
<button
type="button"
className="w-full aspect-square bg-background-muted rounded-lg overflow-hidden shadow-sm focus:outline-none focus:ring-2 focus:ring-primary-500"
onClick={() =>
handleSetCover(item.id)
}
title="Click to set as cover photo"
>
<img
src={getImageUrl(
item.storageKey,
)}
alt={
item.caption ||
`Room photo ${index + 1}`
}
className="w-full h-full object-cover"
loading="lazy"
/>
</button>
{item.isCover && (
<div className="absolute top-1.5 left-1.5">
<span className="bg-primary-600 text-foreground-inverse text-xs font-medium px-2 py-0.5 rounded-full flex items-center gap-1">
<Check className="h-3 w-3" />
Cover
</span>
</div>
)}
{!item.isCover && (
<div className="absolute top-1.5 left-1.5">
<span className="bg-overlay-dark text-foreground-inverse text-xs font-medium w-5 h-5 rounded-full flex items-center justify-center">
{index + 1}
</span>
</div>
)}
</li>
))}
</ul>
</div>
)}
</div>
)}
{/* Step 3: Room Summary / Add Another */}
{currentStep === 3 && (
<div className="space-y-4">
<h3 className="text-md font-semibold text-foreground-default border-b pb-2">
Rooms Added
</h3>
{rooms.length === 0 ? (
<div className="text-center py-8 border border-border-default rounded-lg bg-background-muted">
<p className="text-foreground-muted text-sm">
No rooms added yet.
</p>
</div>
) : (
<ul className="space-y-3 list-none p-0 m-0">
{rooms.map((room, index) => (
<li
key={room.roomId || index}
className="flex items-center gap-4 p-4 border border-border-default rounded-lg bg-background-muted"
>
<div className="flex items-center justify-center w-10 h-10 rounded-full bg-primary-100 text-primary-700 font-semibold text-sm flex-shrink-0">
{index + 1}
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-foreground-default">
{room.name ||
getRoomTypeName(
room.roomType,
)}
</p>
<p className="text-xs text-foreground-muted">
{getRoomTypeName(
room.roomType,
)}
{room.areaSqft
? ` \u00B7 ${room.areaSqft} sq ft`
: ""}
</p>
</div>
<div className="flex items-center gap-1 text-foreground-muted">
<Camera className="h-4 w-4" />
<span className="text-xs">
{room.photoCount}
</span>
</div>
{index === 0 && (
<span className="text-xs bg-primary-100 text-primary-700 px-2 py-0.5 rounded-full font-medium">
Featured
</span>
)}
</li>
))}
</ul>
)}
<div className="flex flex-col sm:flex-row gap-3 pt-2">
<Button
type="button"
variant="outline"
onClick={handleAddAnotherRoom}
className="flex items-center gap-2"
>
<Plus className="h-4 w-4" />
Add Another Room
</Button>
</div>
</div>
)}
</>
);
// ─── Mobile: full-screen page (matches DrawerDialog pattern) ────────
if (isMobile) {
return (
<div className="fixed inset-0 z-[60] flex flex-col bg-background-base animate-page-in">
{/* Header */}
<div className="flex h-14 items-center gap-3 border-b border-border-default bg-background-elevated px-4 flex-shrink-0">
<button
type="button"
onClick={handleClose}
className="p-2 -ml-2 text-foreground-muted hover:text-foreground-default rounded-md"
aria-label="Go back"
>
<ArrowLeft className="h-5 w-5" />
</button>
<h2 className="text-lg font-semibold text-foreground-default">
New Project
</h2>
</div>
{/* Progress */}
<div className="px-4 pt-3 pb-1 bg-background-base flex-shrink-0">
{progressHeader}
</div>
{/* Content */}
<div className="flex-1 overflow-y-auto p-4">
{stepContent}
</div>
{/* Footer */}
<div className="flex-shrink-0 px-4 py-4 border-t border-border-default bg-background-elevated">
{footerContent}
</div>
</div>
);
}
// ─── Desktop: dialog overlay ────────────────────────────────────────
return (
<div
className="fixed inset-0 z-50 flex flex-col items-center justify-center p-4"
tabIndex={-1}
>
{/* Backdrop */}
<button
type="button"
aria-label="Close modal"
className="fixed inset-0 bg-black/50 cursor-default"
onClick={handleClose}
tabIndex={-1}
/>
<div
ref={dialogRef}
role="dialog"
aria-modal="true"
aria-labelledby="project-wizard-dialog-title"
onKeyDown={handleFocusTrap}
className="relative flex flex-col bg-background-elevated w-full max-w-3xl mx-auto max-h-[90vh] rounded-lg shadow-xl"
>
{/* Header */}
<div className="bg-background-elevated border-b px-6 py-4 z-10 rounded-t-lg flex-shrink-0">
<div className="flex items-center justify-between mb-3">
<h2
id="project-wizard-dialog-title"
className="text-lg font-semibold"
>
New Project
</h2>
<button
type="button"
onClick={handleClose}
aria-label="Close"
className="text-foreground-subtle hover:text-foreground-muted"
>
<X className="h-5 w-5" />
</button>
</div>
{progressHeader}
</div>
{/* Scrollable content */}
<div className="flex-1 overflow-y-auto p-6">
{stepContent}
</div>
{/* Footer */}
<div className="bg-background-elevated border-t px-6 py-4 rounded-b-lg flex-shrink-0">
{footerContent}
</div>
</div>
</div>
);
}
|