Skip to content

Commit 9095dbe

Browse files
Merge pull request #14 from StreetSupport/staging
Merge staging into main
2 parents 07fad00 + fa20f44 commit 9095dbe

File tree

16 files changed

+109
-104
lines changed

16 files changed

+109
-104
lines changed

src/app/advice/[id]/edit/page.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ export default function AdviceEditPage() {
4646
const [error, setError] = useState<string | null>(null);
4747
const [saving, setSaving] = useState(false);
4848
const [validationErrors, setValidationErrors] = useState<ValidationError[]>([]);
49-
const [showCancelModal, setShowCancelModal] = useState(false);
49+
const [showConfirmModal, setshowConfirmModal] = useState(false);
5050
const [locations, setLocations] = useState<Array<{ Key: string; Name: string }>>([]);
51-
const [editorResetKey, setEditorResetKey] = useState(0);
5251
const { setAdviceTitle } = useBreadcrumb();
5352

5453
// Form state
@@ -174,24 +173,17 @@ export default function AdviceEditPage() {
174173

175174
const handleCancel = () => {
176175
if (JSON.stringify(formData) !== JSON.stringify(originalData)) {
177-
setShowCancelModal(true);
176+
setshowConfirmModal(true);
178177
} else {
179-
router.push(`/advice/${id}`);
178+
router.push(`/advice`);
180179
}
181180
};
182181

183182
const confirmCancel = () => {
184-
// Revert to original data
185-
if (originalData) {
186-
setFormData(JSON.parse(JSON.stringify(originalData)));
187-
setValidationErrors([]);
188-
setEditorResetKey(prev => prev + 1); // Force editor remount
189-
}
190-
setShowCancelModal(false);
183+
setshowConfirmModal(false);
184+
router.push('/advice');
191185
};
192186

193-
const hasChanges = JSON.stringify(formData) !== JSON.stringify(originalData);
194-
195187
// Show loading while checking authorization or fetching data
196188
if (isChecking || loading) {
197189
return <LoadingSpinner />;
@@ -268,7 +260,6 @@ export default function AdviceEditPage() {
268260
placeholder="Enter the advice content..."
269261
minHeight="400px"
270262
required
271-
resetKey={editorResetKey}
272263
/>
273264
</div>
274265

@@ -293,7 +284,7 @@ export default function AdviceEditPage() {
293284
<Button
294285
type="submit"
295286
variant="primary"
296-
disabled={saving || !hasChanges}
287+
disabled={saving}
297288
>
298289
{saving ? 'Saving...' : 'Save Changes'}
299290
</Button>
@@ -304,13 +295,13 @@ export default function AdviceEditPage() {
304295

305296
{/* Cancel Confirmation Modal */}
306297
<ConfirmModal
307-
isOpen={showCancelModal}
308-
onClose={() => setShowCancelModal(false)}
298+
isOpen={showConfirmModal}
299+
onClose={() => setshowConfirmModal(false)}
309300
onConfirm={confirmCancel}
310301
title="Close without saving?"
311302
message="You may lose unsaved changes."
312303
variant="warning"
313-
confirmLabel="Discard changes"
304+
confirmLabel="Close Without Saving"
314305
cancelLabel="Continue Editing"
315306
/>
316307
</div>

src/app/advice/new/page.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,23 @@ export default function NewAdvicePage() {
3939

4040
const [saving, setSaving] = useState(false);
4141
const [validationErrors, setValidationErrors] = useState<ValidationError[]>([]);
42-
const [showCancelModal, setShowCancelModal] = useState(false);
42+
const [showConfirmModal, setshowConfirmModal] = useState(false);
4343
const [locations, setLocations] = useState<Array<{ Key: string; Name: string }>>([]);
44-
const [editorResetKey, setEditorResetKey] = useState(0);
4544
const { setAdviceTitle } = useBreadcrumb();
4645

4746
// Form state
4847
const [formData, setFormData] = useState({
4948
LocationKey: '',
5049
Title: '',
5150
Body: '',
52-
SortPosition: 0,
51+
SortPosition: 1,
5352
});
5453

5554
const initialFormData = {
5655
LocationKey: '',
5756
Title: '',
5857
Body: '',
59-
SortPosition: 0,
58+
SortPosition: 1,
6059
};
6160

6261
useEffect(() => {
@@ -130,18 +129,15 @@ export default function NewAdvicePage() {
130129

131130
const handleCancel = () => {
132131
if (JSON.stringify(formData) !== JSON.stringify(initialFormData)) {
133-
setShowCancelModal(true);
132+
setshowConfirmModal(true);
134133
} else {
135134
router.push('/advice');
136135
}
137136
};
138137

139138
const confirmCancel = () => {
140-
// Revert to initial data
141-
setFormData(JSON.parse(JSON.stringify(initialFormData)));
142-
setValidationErrors([]);
143-
setEditorResetKey(prev => prev + 1); // Force editor remount
144-
setShowCancelModal(false);
139+
setshowConfirmModal(false);
140+
router.push('/advice');
145141
};
146142

147143
// const hasData = JSON.stringify(formData) !== JSON.stringify(initialFormData);
@@ -213,7 +209,6 @@ export default function NewAdvicePage() {
213209
placeholder="Enter the advice content..."
214210
minHeight="400px"
215211
required
216-
resetKey={editorResetKey}
217212
/>
218213
</div>
219214

@@ -249,13 +244,13 @@ export default function NewAdvicePage() {
249244

250245
{/* Cancel Confirmation Modal */}
251246
<ConfirmModal
252-
isOpen={showCancelModal}
253-
onClose={() => setShowCancelModal(false)}
247+
isOpen={showConfirmModal}
248+
onClose={() => setshowConfirmModal(false)}
254249
onConfirm={confirmCancel}
255250
title="Close without saving?"
256251
message="You may lose unsaved changes."
257252
variant="warning"
258-
confirmLabel="Discard changes"
253+
confirmLabel="Close Without Saving"
259254
cancelLabel="Continue Editing"
260255
/>
261256
</div>

src/app/banners/[id]/edit/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ export default function EditBannerPage() {
271271
}
272272
};
273273

274+
const handleCancel = () => {
275+
router.push('/banners');
276+
};
277+
274278
// Show loading while checking authorization or fetching data
275279
if (isChecking || loading) {
276280
return <LoadingSpinner />;
@@ -313,6 +317,7 @@ return (
313317
onSave={handleSave}
314318
saving={saving}
315319
validationErrors={validationErrors}
320+
onCancel={handleCancel}
316321
/>
317322
</div>
318323
</div>

src/app/banners/new/page.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ export default function NewBannerPage() {
143143
}
144144
};
145145

146+
const handleCancel = () => {
147+
router.push('/banners');
148+
};
149+
146150
// Show loading while checking authorization
147151
if (isChecking) {
148152
return <LoadingSpinner />;
@@ -173,6 +177,7 @@ export default function NewBannerPage() {
173177
onSave={handleSave}
174178
saving={saving}
175179
validationErrors={validationErrors}
180+
onCancel={handleCancel}
176181
/>
177182
</div>
178183
</div>

src/app/location-logos/[id]/edit/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ export default function EditLocationLogoPage() {
9797
}
9898
};
9999

100+
const handleCancel = () => {
101+
router.push('/location-logos');
102+
};
103+
100104
if (isChecking || loading) {
101105
return <LoadingSpinner />;
102106
}
@@ -128,7 +132,7 @@ export default function EditLocationLogoPage() {
128132
<LocationLogoForm
129133
initialData={logo}
130134
onSubmit={handleSubmit}
131-
onCancel={() => {}}
135+
onCancel={handleCancel}
132136
isEdit={true}
133137
saving={saving}
134138
/>

src/app/location-logos/new/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export default function CreateLocationLogoPage() {
5151
}
5252
};
5353

54+
const handleCancel = () => {
55+
router.push('/location-logos');
56+
};
57+
5458
return (
5559
<div className="min-h-screen bg-brand-q">
5660
<PageHeader title="Add New Location Logo" />
@@ -59,7 +63,7 @@ export default function CreateLocationLogoPage() {
5963
<div className="max-w-3xl mx-auto py-8">
6064
<LocationLogoForm
6165
onSubmit={handleSubmit}
62-
onCancel={() => {}}
66+
onCancel={handleCancel}
6367
saving={saving}
6468
/>
6569
</div>

src/app/resources/[key]/edit/page.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export default function ResourceEditPage() {
5050
const [validationErrors, setValidationErrors] = useState<ValidationError[]>([]);
5151
const [showCancelModal, setShowCancelModal] = useState(false);
5252
const [hasUploadedFiles, setHasUploadedFiles] = useState(false); // Track if any files were uploaded
53-
const [editorResetKey, setEditorResetKey] = useState(0);
5453

5554
// Form state
5655
const [formData, setFormData] = useState({
@@ -210,20 +209,13 @@ export default function ResourceEditPage() {
210209
if (JSON.stringify(formData) !== JSON.stringify(originalData)) {
211210
setShowCancelModal(true);
212211
} else {
213-
// No changes, reset form to default (deep clone to avoid reference issues)
214-
setFormData(JSON.parse(JSON.stringify(originalData)));
215-
setValidationErrors([]);
216-
setHasUploadedFiles(false);
212+
confirmCancel();
217213
}
218214
};
219215

220216
const confirmCancel = () => {
221-
// Revert to original data (deep clone to avoid reference issues)
222-
setFormData(JSON.parse(JSON.stringify(originalData)));
223-
setValidationErrors([]);
224-
setEditorResetKey(prev => prev + 1); // Force editor remount
225217
setShowCancelModal(false);
226-
setHasUploadedFiles(false); // Reset file upload tracking
218+
router.push('/resources');
227219
};
228220

229221
// LinkList Management Functions
@@ -357,7 +349,6 @@ export default function ResourceEditPage() {
357349
onChange={(value) => setFormData({ ...formData, Body: value })}
358350
placeholder="Enter the main resource content..."
359351
minHeight="400px"
360-
resetKey={editorResetKey}
361352
/>
362353
</div>
363354

@@ -554,7 +545,7 @@ export default function ResourceEditPage() {
554545
title="Close without saving?"
555546
message="You may lose unsaved changes."
556547
variant="warning"
557-
confirmLabel="Discard changes"
548+
confirmLabel="Close Without Saving"
558549
cancelLabel="Continue Editing"
559550
/>
560551
</div>

src/app/swep-banners/[locationSlug]/edit/page.tsx

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export default function SwepEditPage() {
4343
const [imagePreview, setImagePreview] = useState<string | null>(null);
4444
const [imageRemoved, setImageRemoved] = useState(false);
4545
const [showConfirmModal, setShowConfirmModal] = useState(false);
46-
const [editorResetKey, setEditorResetKey] = useState(0);
4746
const fileInputRef = useRef<HTMLInputElement>(null);
4847

4948
const [formData, setFormData] = useState<ISwepBannerFormData>({
@@ -201,28 +200,13 @@ export default function SwepEditPage() {
201200
if (originalData && JSON.stringify(formData) !== JSON.stringify(originalData)) {
202201
setShowConfirmModal(true);
203202
} else {
204-
// No changes, reset form to defaults
205-
if (originalData) {
206-
setFormData(originalData);
207-
setImageFile(null);
208-
setImagePreview(swep?.Image || null);
209-
setImageRemoved(false);
210-
setValidationErrors([]);
211-
}
203+
confirmCancel();
212204
}
213205
};
214206

215207
const confirmCancel = () => {
216-
// Revert to original data
217-
if (originalData) {
218-
setFormData(originalData);
219-
setImageFile(null);
220-
setImagePreview(swep?.Image || null);
221-
setImageRemoved(false);
222-
setValidationErrors([]);
223-
setEditorResetKey(prev => prev + 1); // Force editor remount
224-
}
225208
setShowConfirmModal(false);
209+
router.push('/swep-banners');
226210
};
227211

228212
// Show loading while checking authorization or fetching data
@@ -372,7 +356,6 @@ export default function SwepEditPage() {
372356
placeholder="Enter the SWEP banner body content..."
373357
required
374358
minHeight="300px"
375-
resetKey={editorResetKey}
376359
/>
377360

378361
{/* Emergency Contact Section */}
@@ -449,7 +432,7 @@ export default function SwepEditPage() {
449432
title="Close without saving?"
450433
message="You may lose unsaved changes."
451434
variant="warning"
452-
confirmLabel="Discard changes"
435+
confirmLabel="Close Without Saving"
453436
cancelLabel="Continue Editing"
454437
/>
455438
</div>

src/components/banners/BannerEditor.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface BannerEditorProps {
4343
onDataChange: (data: IBannerFormData) => void;
4444
onSave: (data: IBannerFormData) => void;
4545
saving?: boolean;
46-
onCancel?: () => void;
46+
onCancel: () => void;
4747
errorMessage?: string | null;
4848
validationErrors?: IValidationError[];
4949
}
@@ -303,6 +303,16 @@ export function BannerEditor({ initialData, onDataChange, onSave, saving = false
303303
newData = handleTemplateTypeChange(newTemplateType, newData);
304304
}
305305

306+
// Handle background type change: when switching away from IMAGE, reset Background.Value
307+
if (path === 'Background.Type') {
308+
const newBackgroundType = value as BackgroundType;
309+
const previousBackgroundType = (prev as IBannerFormData).Background.Type;
310+
311+
if (previousBackgroundType === BackgroundType.IMAGE && newBackgroundType !== BackgroundType.IMAGE) {
312+
newData.Background.Value = '#38ae8e';
313+
}
314+
}
315+
306316
// Walk the path, cloning each branch as we go using indexable records
307317
let current: Record<string, unknown> = newData as unknown as Record<string, unknown>;
308318
let source: Record<string, unknown> = prev as unknown as Record<string, unknown>;
@@ -399,7 +409,7 @@ export function BannerEditor({ initialData, onDataChange, onSave, saving = false
399409
setFormData(prev => {
400410
if ((prev.PartnershipCharter?.PartnerLogos?.length || 0) >= 5) {
401411
// Optionally, set an error message to inform the user
402-
setErrors(e => ({ ...e, PartnerLogos: 'You can only upload a maximum of 5 logos.' }));
412+
setErrors(e => ({ ...e, 'Partner Logos': 'You can only upload a maximum of 5 logos.' }));
403413
return prev;
404414
}
405415
return {
@@ -445,22 +455,13 @@ export function BannerEditor({ initialData, onDataChange, onSave, saving = false
445455
if (JSON.stringify(formData) !== JSON.stringify(originalDataRef.current)) {
446456
setShowConfirmModal(true);
447457
} else {
448-
// No changes, just close/revert
449-
if (onCancel) {
450-
onCancel();
451-
}
458+
confirmCancel();
452459
}
453460
};
454461

455462
const confirmCancel = () => {
456463
setShowConfirmModal(false);
457-
458-
// Restore the original data
459-
setFormData(JSON.parse(JSON.stringify(originalDataRef.current)));
460-
461-
if (onCancel) {
462-
onCancel();
463-
}
464+
onCancel();
464465
};
465466

466467
const cleanTemplateData = (data: IBannerFormData): IBannerFormData => {
@@ -1284,7 +1285,7 @@ export function BannerEditor({ initialData, onDataChange, onSave, saving = false
12841285
title="Close without saving?"
12851286
message="You may lose unsaved changes."
12861287
variant="warning"
1287-
confirmLabel="Discard changes"
1288+
confirmLabel="Close Without Saving"
12881289
cancelLabel="Continue Editing"
12891290
/>
12901291
</div>

0 commit comments

Comments
 (0)