Fix admin panel dropdown reset on window focus
This commit is contained in:
@@ -154,16 +154,6 @@ export default function AdminDashboard() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAllData();
|
fetchAllData();
|
||||||
|
|
||||||
// Refresh when window regains focus
|
|
||||||
const handleFocus = () => {
|
|
||||||
fetchAllData();
|
|
||||||
};
|
|
||||||
window.addEventListener('focus', handleFocus);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
window.removeEventListener('focus', handleFocus);
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Sorting logic
|
// Sorting logic
|
||||||
@@ -721,7 +711,21 @@ function FilamentForm({
|
|||||||
cena_refill: refillPrice || 3499,
|
cena_refill: refillPrice || 3499,
|
||||||
cena_spulna: spulnaPrice || 3999,
|
cena_spulna: spulnaPrice || 3999,
|
||||||
});
|
});
|
||||||
}, [filament, availableColors]);
|
}, [filament]);
|
||||||
|
|
||||||
|
// Update prices when color selection changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (formData.boja && availableColors.length > 0) {
|
||||||
|
const colorData = availableColors.find(c => c.name === formData.boja);
|
||||||
|
if (colorData) {
|
||||||
|
setFormData(prev => ({
|
||||||
|
...prev,
|
||||||
|
cena_refill: colorData.cena_refill || prev.cena_refill,
|
||||||
|
cena_spulna: colorData.cena_spulna || prev.cena_spulna,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [formData.boja, availableColors.length]);
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement>) => {
|
||||||
const { name, value } = e.target;
|
const { name, value } = e.target;
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ INSERT INTO colors (name, hex) VALUES
|
|||||||
('Silver', '#A6A9AA'),
|
('Silver', '#A6A9AA'),
|
||||||
('Blue Grey', '#5B6579'),
|
('Blue Grey', '#5B6579'),
|
||||||
('Dark Gray', '#555555'),
|
('Dark Gray', '#555555'),
|
||||||
('Black', '#000000')
|
('Black', '#000000'),
|
||||||
|
('Latte Brown', '#D3B7A7')
|
||||||
ON CONFLICT (name)
|
ON CONFLICT (name)
|
||||||
DO UPDATE SET hex = EXCLUDED.hex;
|
DO UPDATE SET hex = EXCLUDED.hex;
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ WHERE c.name IN (
|
|||||||
'Mistletoe Green', 'Pink', 'Hot Pink', 'Magenta', 'Red',
|
'Mistletoe Green', 'Pink', 'Hot Pink', 'Magenta', 'Red',
|
||||||
'Maroon Red', 'Purple', 'Indigo Purple', 'Turquoise', 'Cyan',
|
'Maroon Red', 'Purple', 'Indigo Purple', 'Turquoise', 'Cyan',
|
||||||
'Cobalt Blue', 'Blue', 'Brown', 'Cocoa Brown', 'Bronze',
|
'Cobalt Blue', 'Blue', 'Brown', 'Cocoa Brown', 'Bronze',
|
||||||
'Gray', 'Silver', 'Blue Grey', 'Dark Gray', 'Black'
|
'Gray', 'Silver', 'Blue Grey', 'Dark Gray', 'Black', 'Latte Brown'
|
||||||
)
|
)
|
||||||
AND NOT EXISTS (
|
AND NOT EXISTS (
|
||||||
SELECT 1 FROM filaments f
|
SELECT 1 FROM filaments f
|
||||||
@@ -75,7 +76,7 @@ AND boja IN (
|
|||||||
'Mistletoe Green', 'Pink', 'Hot Pink', 'Magenta', 'Red',
|
'Mistletoe Green', 'Pink', 'Hot Pink', 'Magenta', 'Red',
|
||||||
'Maroon Red', 'Purple', 'Indigo Purple', 'Turquoise', 'Cyan',
|
'Maroon Red', 'Purple', 'Indigo Purple', 'Turquoise', 'Cyan',
|
||||||
'Cobalt Blue', 'Blue', 'Brown', 'Cocoa Brown', 'Bronze',
|
'Cobalt Blue', 'Blue', 'Brown', 'Cocoa Brown', 'Bronze',
|
||||||
'Gray', 'Silver', 'Blue Grey', 'Dark Gray', 'Black'
|
'Gray', 'Silver', 'Blue Grey', 'Dark Gray', 'Black', 'Latte Brown'
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Zero out ALL other filaments (not PLA Basic with these specific colors)
|
-- Zero out ALL other filaments (not PLA Basic with these specific colors)
|
||||||
@@ -90,6 +91,6 @@ WHERE NOT (
|
|||||||
'Mistletoe Green', 'Pink', 'Hot Pink', 'Magenta', 'Red',
|
'Mistletoe Green', 'Pink', 'Hot Pink', 'Magenta', 'Red',
|
||||||
'Maroon Red', 'Purple', 'Indigo Purple', 'Turquoise', 'Cyan',
|
'Maroon Red', 'Purple', 'Indigo Purple', 'Turquoise', 'Cyan',
|
||||||
'Cobalt Blue', 'Blue', 'Brown', 'Cocoa Brown', 'Bronze',
|
'Cobalt Blue', 'Blue', 'Brown', 'Cocoa Brown', 'Bronze',
|
||||||
'Gray', 'Silver', 'Blue Grey', 'Dark Gray', 'Black'
|
'Gray', 'Silver', 'Blue Grey', 'Dark Gray', 'Black', 'Latte Brown'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
45
database/migrations/016_add_tpu_colors.sql
Normal file
45
database/migrations/016_add_tpu_colors.sql
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
-- Migration: Add new TPU colors
|
||||||
|
-- Adds Frozen to TPU 90A and Neon Orange to TPU 85A
|
||||||
|
|
||||||
|
-- First, add the new colors to the colors table
|
||||||
|
INSERT INTO colors (name, hex) VALUES
|
||||||
|
('Frozen', '#B2E2F5'),
|
||||||
|
('Neon Orange', '#F68A1B')
|
||||||
|
ON CONFLICT (name)
|
||||||
|
DO UPDATE SET hex = EXCLUDED.hex;
|
||||||
|
|
||||||
|
-- Add TPU 90A filament for Frozen color
|
||||||
|
INSERT INTO filaments (tip, finish, boja, boja_hex, refill, spulna, kolicina, cena)
|
||||||
|
SELECT
|
||||||
|
'TPU' as tip,
|
||||||
|
'90A' as finish,
|
||||||
|
'Frozen' as boja,
|
||||||
|
'#B2E2F5' as boja_hex,
|
||||||
|
0 as refill,
|
||||||
|
0 as spulna,
|
||||||
|
0 as kolicina,
|
||||||
|
'0' as cena
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM filaments
|
||||||
|
WHERE tip = 'TPU'
|
||||||
|
AND finish = '90A'
|
||||||
|
AND boja = 'Frozen'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Add TPU 85A filament for Neon Orange color
|
||||||
|
INSERT INTO filaments (tip, finish, boja, boja_hex, refill, spulna, kolicina, cena)
|
||||||
|
SELECT
|
||||||
|
'TPU' as tip,
|
||||||
|
'85A' as finish,
|
||||||
|
'Neon Orange' as boja,
|
||||||
|
'#F68A1B' as boja_hex,
|
||||||
|
0 as refill,
|
||||||
|
0 as spulna,
|
||||||
|
0 as kolicina,
|
||||||
|
'0' as cena
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM filaments
|
||||||
|
WHERE tip = 'TPU'
|
||||||
|
AND finish = '85A'
|
||||||
|
AND boja = 'Neon Orange'
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user