Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dashboard",
"version": "1.0.0",
"version": "1.1.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -17,7 +17,7 @@
},
"dependencies": {
"@heroicons/react": "^2.2.0",
"@pharmatech/sdk": "^0.4.21",
"@pharmatech/sdk": "^0.4.22",
"@react-google-maps/api": "^2.20.6",
"@react-pdf/renderer": "^4.3.0",
"blob-stream": "^0.1.3",
Expand Down
3 changes: 2 additions & 1 deletion src/app/(dashboard)/coupons/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ export default function CouponsPage() {
return (
<Badge
variant="filled"
color={isActive ? 'success' : 'info'}
color={isActive ? 'success' : 'danger'}
size="small"
borderRadius="square"
>
{isActive ? 'Activa' : 'Finalizada'}
</Badge>
Expand Down
16 changes: 5 additions & 11 deletions src/app/(dashboard)/products/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default function EditProductPage() {
[],
);
const { token } = useAuth();
const [manufacturerId, setManufacturerId] = useState('');
const [selectedManufacturer, setSelectedManufacturer] = useState('');
const [categories, setCategories] = useState<CategoryResponse[]>([]);
const [categoryId, setCategoryId] = useState('');
Expand Down Expand Up @@ -99,11 +98,6 @@ export default function EditProductPage() {
fetchProduct();
}, [fetchProduct]);

useEffect(() => {
const selected = manufacturers.find((m) => m.name === selectedManufacturer);
setManufacturerId(selected ? selected.id : '');
}, [selectedManufacturer, manufacturers]);

useEffect(() => {
const selected = categories.find((c) => c.name === selectedCategory);
setCategoryId(selected ? selected.id : '');
Expand All @@ -115,7 +109,7 @@ export default function EditProductPage() {
genericName,
description,
priority,
manufacturerId,
manufacturerId: selectedManufacturer,
});

if (!result.success) {
Expand All @@ -139,19 +133,19 @@ export default function EditProductPage() {
name,
description,
priority: parseInt(priority),
manufacturerId,
manufacturerId: selectedManufacturer,
};

try {
await api.genericProduct.update(id, payload, token);
for (const url of imageUrls) {
await api.productImage.create(id, { url });
await api.productImage.create(id, { url }, token);
}
console.log('Category ID:', categoryId, categoryId);
if (currentCategory) {
await api.productCategory.delete(id, currentCategory.id);
await api.productCategory.delete(id, currentCategory.id, token);
}
await api.productCategory.create(id, categoryId);
await api.productCategory.create(id, categoryId, token);
toast.success('Producto actualizado con exito');
setTimeout(() => {
router.push('/products');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ export default function EditProductPresentationPage() {
// Convert to cents
payload.price = Number((payload.price * 100).toFixed(0));
try {
await api.productPresentation.update(productId, presentationId, payload);
await api.productPresentation.update(
productId,
presentationId,
payload,
token,
);
toast.success('Presentación actualizada exitosamente');
setTimeout(() => {
router.push(`/products/${productId}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function ViewProductPresentationPage() {
}

try {
await api.productPresentation.delete(productId, presentationId);
await api.productPresentation.delete(productId, presentationId, token);
toast.success('Presentación eliminada exitosamente');
setTimeout(() => {
router.push(`/products/${productId}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function AddProductPresentationPage() {
// Convert to cents
payload.price = Number((payload.price * 100).toFixed(0));
try {
await api.productPresentation.create(productId, payload);
await api.productPresentation.create(productId, payload, token);
toast.success('Presentación añadida al producto');
setTimeout(() => {
router.push(`/products/${productId}`);
Expand Down
15 changes: 4 additions & 11 deletions src/app/(dashboard)/products/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export default function NewGenericProductPage() {
const [genericName, setGenericName] = useState('');
const [description, setDescription] = useState('');
const [priority, setPriority] = useState('');
const [manufacturerId, setManufacturerId] = useState('');
const [manufacturers, setManufacturers] = useState<ManufacturerResponse[]>(
[],
);
const [selectedManufacturer, setSelectedManufacturer] = useState('');
const [selectedManufacturer, setSelectedManufacturer] = useState<string>('');
const [errors, setErrors] = useState<Record<string, string>>({});

useEffect(() => {
Expand All @@ -39,20 +38,15 @@ export default function NewGenericProductPage() {
fetchManufacturers();
}, []);

useEffect(() => {
const selected = manufacturers.find((m) => m.name === selectedManufacturer);
setManufacturerId(selected ? selected.id : '');
}, [selectedManufacturer, manufacturers]);

const handleSubmit = async () => {
const result = newGenericProductSchema.safeParse({
name,
genericName,
description,
priority,
manufacturerId,
manufacturerId: selectedManufacturer,
});

console.log('Validation result:', result);
if (!result.success) {
const { fieldErrors } = result.error.flatten();
setErrors({
Expand All @@ -79,7 +73,7 @@ export default function NewGenericProductPage() {
genericName,
description,
priority: parseInt(priority),
manufacturerId,
manufacturerId: selectedManufacturer,
};

await api.genericProduct.create(payload, token);
Expand All @@ -89,7 +83,6 @@ export default function NewGenericProductPage() {
setGenericName('');
setDescription('');
setPriority('');
setManufacturerId('');
setSelectedManufacturer('');
setErrors({});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/(dashboard)/promos/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default function PromosPage() {
<Badge
variant="filled"
color={status === 'Activa' ? 'success' : 'danger'}
size="medium"
size="small"
borderRadius="square"
>
{status}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Image/ImageUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default function ImageUpload({
const handleRemoveFile = async (file: FileWithProgress) => {
try {
if (file.fromBackend) {
await api.productImage.delete(productId, file.id);
await api.productImage.delete(productId, file.id, token!);
toast.success('Imagen eliminada del backend');
} else {
if (file.previewUrl) URL.revokeObjectURL(file.previewUrl);
Expand Down
Loading