From 90d06a8b66d951551aa21a6334b029f3e99dfd50 Mon Sep 17 00:00:00 2001 From: rajaoktf Date: Tue, 14 Oct 2025 16:32:00 +0700 Subject: [PATCH] conditional update download csv for staging & prod --- src/lib/helpers.ts | 3 +++ src/pages/notification/blocks/AddDialog.tsx | 3 ++- vite.config.ts | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index c6a9c30..17975f0 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -56,3 +56,6 @@ export function deepMerge(obj1: any, obj2: any): any { export function uniqueID(): string { return (Date.now() + Math.floor(Math.random() * 1000)).toString(); } + +const baseUrl = import.meta.env?.VITE_BASE_URL || '/'; +export const TEMPLATE_CSV_URL = `${baseUrl}template_notification.csv`; diff --git a/src/pages/notification/blocks/AddDialog.tsx b/src/pages/notification/blocks/AddDialog.tsx index dd154f3..bbbea21 100644 --- a/src/pages/notification/blocks/AddDialog.tsx +++ b/src/pages/notification/blocks/AddDialog.tsx @@ -30,6 +30,7 @@ import { Check, ChevronDown, X } from 'lucide-react'; import { initialStateNotification, selectedNotification, validateFormNotification } from './Types'; import { useDebounce } from './useDebounce'; import Papa from 'papaparse'; +import { TEMPLATE_CSV_URL } from '@/lib/helpers'; const API_URL_CUSTOMER = apiConfig.service_customer; const API_URL_NOTIFICATION = apiConfig.service_notification; @@ -481,7 +482,7 @@ const AddDialog = () => { /> diff --git a/vite.config.ts b/vite.config.ts index 43f2af0..f4335af 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,13 +2,22 @@ import { fileURLToPath, URL } from 'node:url'; import react from '@vitejs/plugin-react'; import { defineConfig, loadEnv } from 'vite'; import tailwindcss from 'tailwindcss'; + export default ({ mode }) => { - process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }; + const env = loadEnv(mode, process.cwd(), ''); + return defineConfig({ - base: process.env.VITE_BASE_URL || '/', + base: env.VITE_BASE_URL || '/', plugins: [react()], css: { postcss: { plugins: [tailwindcss()] } }, - resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } }, + resolve: { + alias: { + '@': fileURLToPath(new URL('./src', import.meta.url)) + } + }, + define: { + 'import.meta.env.VITE_BASE_URL': JSON.stringify(env.VITE_BASE_URL) + }, build: { chunkSizeWarningLimit: 3000 } }); };