Álvaro Valenzuela Valdes commited on
Commit
5581012
·
1 Parent(s): 40fe703

🚀 Fix: Corrected CompanyProfile syntax and restored state

Browse files
frontend/components/CompanyProfile.tsx CHANGED
@@ -1,6 +1,6 @@
1
  "use client";
2
 
3
- import { useMemo, useState } from "react";
4
  import type { CompanyProfile as CompanyProfileType } from "../lib/types";
5
 
6
  type Props = {
@@ -17,14 +17,34 @@ export default function CompanyProfile({ profile, onSave }: Props) {
17
  const [regionsStr, setRegionsStr] = useState(profile.regions?.join(", ") || "");
18
  const [docsStr, setDocsStr] = useState(profile.documents_available?.join(", ") || "");
19
 
20
- const handleSave = () => {
21
- onSave({
22
- ...form,
23
- services: servicesStr.split(",").map((s) => s.trim()).filter(Boolean),
24
- certifications: certsStr.split(",").map((s) => s.trim()).filter(Boolean),
25
- regions: regionsStr.split(",").map((s) => s.trim()).filter(Boolean),
26
- documents_available: docsStr.split(",").map((s) => s.trim()).filter(Boolean),
27
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  };
29
 
30
  return (
@@ -103,10 +123,37 @@ export default function CompanyProfile({ profile, onSave }: Props) {
103
  <button
104
  type="button"
105
  onClick={handleSave}
106
- className="group relative overflow-hidden rounded-2xl bg-cyan px-8 py-4 font-bold text-slate-950 transition hover:bg-sky hover:scale-[1.02] active:scale-[0.98] shadow-lg shadow-cyan/20"
 
 
 
 
 
107
  >
108
- <span className="relative z-10">Save Profile</span>
109
- <div className="absolute inset-0 bg-gradient-to-r from-white/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity" />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  </button>
111
  </div>
112
  </div>
 
1
  "use client";
2
 
3
+ import { useState } from "react";
4
  import type { CompanyProfile as CompanyProfileType } from "../lib/types";
5
 
6
  type Props = {
 
17
  const [regionsStr, setRegionsStr] = useState(profile.regions?.join(", ") || "");
18
  const [docsStr, setDocsStr] = useState(profile.documents_available?.join(", ") || "");
19
 
20
+ const [saving, setSaving] = useState(false);
21
+ const [saveStatus, setSaveStatus] = useState<"idle" | "saving" | "success" | "error">("idle");
22
+
23
+ const handleSave = async () => {
24
+ console.log("[CompanyProfile] Clicked Save Profile");
25
+ setSaving(true);
26
+ setSaveStatus("saving");
27
+ try {
28
+ const updatedProfile = {
29
+ ...form,
30
+ services: servicesStr.split(",").map((s) => s.trim()).filter(Boolean),
31
+ certifications: certsStr.split(",").map((s) => s.trim()).filter(Boolean),
32
+ regions: regionsStr.split(",").map((s) => s.trim()).filter(Boolean),
33
+ documents_available: docsStr.split(",").map((s) => s.trim()).filter(Boolean),
34
+ };
35
+
36
+ console.log("[CompanyProfile] Sending to onSave:", updatedProfile);
37
+ await onSave(updatedProfile);
38
+
39
+ setSaveStatus("success");
40
+ setTimeout(() => setSaveStatus("idle"), 3000);
41
+ } catch (e) {
42
+ console.error("[CompanyProfile] Save failed", e);
43
+ setSaveStatus("error");
44
+ setTimeout(() => setSaveStatus("idle"), 3000);
45
+ } finally {
46
+ setSaving(false);
47
+ }
48
  };
49
 
50
  return (
 
123
  <button
124
  type="button"
125
  onClick={handleSave}
126
+ disabled={saving}
127
+ className={`group relative overflow-hidden rounded-2xl px-12 py-5 font-bold text-slate-950 transition-all active:scale-95 shadow-xl ${
128
+ saveStatus === "success" ? "bg-green-500 shadow-green-500/30" :
129
+ saveStatus === "error" ? "bg-red-500 shadow-red-500/30" :
130
+ "bg-cyan hover:bg-sky shadow-cyan/30"
131
+ } ${saving ? "opacity-70 cursor-wait" : "cursor-pointer"}`}
132
  >
133
+ <span className="relative z-10 flex items-center gap-3">
134
+ {saveStatus === "idle" && "Save Profile"}
135
+ {saveStatus === "saving" && (
136
+ <>
137
+ <span className="animate-spin text-xl">⏳</span>
138
+ Saving...
139
+ </>
140
+ )}
141
+ {saveStatus === "success" && (
142
+ <>
143
+ <span className="text-xl">✅</span>
144
+ Saved!
145
+ </>
146
+ )}
147
+ {saveStatus === "error" && (
148
+ <>
149
+ <span className="text-xl">❌</span>
150
+ Error!
151
+ </>
152
+ )}
153
+ </span>
154
+ {saveStatus === "idle" && (
155
+ <div className="absolute inset-0 bg-gradient-to-r from-white/30 to-transparent opacity-0 group-hover:opacity-100 transition-opacity" />
156
+ )}
157
  </button>
158
  </div>
159
  </div>