changes
This commit is contained in:
parent
6929a4802c
commit
3daf9f03d3
@ -20,6 +20,7 @@ import { Link } from 'react-router-dom';
|
|||||||
import Card from '@/components/common/Card';
|
import Card from '@/components/common/Card';
|
||||||
import triggerIcon from '@/assets/trigger.png';
|
import triggerIcon from '@/assets/trigger.png';
|
||||||
import { getManufacturingIndex, getManufacturingMonthlyOverview, autoSubmitSurvey, getManufacturingIndexFiltered } from '@/services/manufacturingIndex/ManufacturingIndex';
|
import { getManufacturingIndex, getManufacturingMonthlyOverview, autoSubmitSurvey, getManufacturingIndexFiltered } from '@/services/manufacturingIndex/ManufacturingIndex';
|
||||||
|
import apiClient from '@/services/api/apiClient';
|
||||||
|
|
||||||
// Import popup components
|
// Import popup components
|
||||||
import ManufacturingTotal from './ManufacturingIndexPopup/ManufacturingTotal';
|
import ManufacturingTotal from './ManufacturingIndexPopup/ManufacturingTotal';
|
||||||
@ -27,6 +28,7 @@ import ISIC2Digit from './ManufacturingIndexPopup/ISIC2Digit';
|
|||||||
import ISIC3Digit from './ManufacturingIndexPopup/ISIC3Digit';
|
import ISIC3Digit from './ManufacturingIndexPopup/ISIC3Digit';
|
||||||
import ISIC4Digit from './ManufacturingIndexPopup/ISIC4Digit';
|
import ISIC4Digit from './ManufacturingIndexPopup/ISIC4Digit';
|
||||||
|
|
||||||
|
|
||||||
// Custom components
|
// Custom components
|
||||||
const SelectField = (props) => (
|
const SelectField = (props) => (
|
||||||
<BaseSelectField
|
<BaseSelectField
|
||||||
@ -62,6 +64,9 @@ const ManufacturingIndex = () => {
|
|||||||
const [surveySubmitLoading, setSurveySubmitLoading] = useState(false);
|
const [surveySubmitLoading, setSurveySubmitLoading] = useState(false);
|
||||||
const [surveySubmitStatus, setSurveySubmitStatus] = useState('');
|
const [surveySubmitStatus, setSurveySubmitStatus] = useState('');
|
||||||
const [surveySubmitError, setSurveySubmitError] = useState(null);
|
const [surveySubmitError, setSurveySubmitError] = useState(null);
|
||||||
|
const [baseYearLoading, setBaseYearLoading] = useState(false);
|
||||||
|
const [baseYearStatus, setBaseYearStatus] = useState('');
|
||||||
|
const [baseYearError, setBaseYearError] = useState('');
|
||||||
const [nextScheduledRun, setNextScheduledRun] = useState(''); // Default value
|
const [nextScheduledRun, setNextScheduledRun] = useState(''); // Default value
|
||||||
const [refreshKey, setRefreshKey] = useState(0);
|
const [refreshKey, setRefreshKey] = useState(0);
|
||||||
|
|
||||||
@ -132,9 +137,7 @@ const ManufacturingIndex = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Debug: Log the actual data structure
|
// Debug: Log the actual data structure
|
||||||
console.log('API Response:', response);
|
|
||||||
console.log('Data Array:', dataArray);
|
|
||||||
console.log('Sample item:', dataArray[0]);
|
|
||||||
|
|
||||||
// Format the data
|
// Format the data
|
||||||
const formattedData = dataArray.map((item, index) => {
|
const formattedData = dataArray.map((item, index) => {
|
||||||
@ -335,6 +338,36 @@ const handleSearchMonth = (e) => {
|
|||||||
setSearchMonth(e.target.value);
|
setSearchMonth(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleBaseYear = async () => {
|
||||||
|
setSurveySubmitLoading(true);
|
||||||
|
setSurveySubmitStatus('');
|
||||||
|
setSurveySubmitError('');
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await apiClient.post('/calculate_base_year', {
|
||||||
|
baseYear: 2022,
|
||||||
|
forceRecalculate: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
setSurveySubmitStatus(
|
||||||
|
response?.data?.message ||
|
||||||
|
'Base year calculation completed successfully.'
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
setSurveySubmitError(
|
||||||
|
error?.response?.data?.message ||
|
||||||
|
error.message ||
|
||||||
|
'Base year calculation failed.'
|
||||||
|
);
|
||||||
|
|
||||||
|
console.error('Error:', error);
|
||||||
|
} finally {
|
||||||
|
setSurveySubmitLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleTriggerData = async () => {
|
const handleTriggerData = async () => {
|
||||||
setError(null);
|
setError(null);
|
||||||
setSurveySubmitStatus('');
|
setSurveySubmitStatus('');
|
||||||
@ -709,9 +742,10 @@ const handleSearchMonth = (e) => {
|
|||||||
Coverage: Manufacturing (ISIC C)
|
Coverage: Manufacturing (ISIC C)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3 w-full sm:w-auto">
|
<div className="flex items-center gap-3">
|
||||||
<div className="flex-1 sm:flex-none w-40">
|
<div className="w-[180px]">
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
|
||||||
<img src="/assets/images/material-symbols_search-rounded.svg" alt="Search" className="h-5 w-5" />
|
<img src="/assets/images/material-symbols_search-rounded.svg" alt="Search" className="h-5 w-5" />
|
||||||
@ -725,31 +759,39 @@ const handleSearchMonth = (e) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center w-auto min-w-[88px]">
|
<div className="flex items-center w-[99px]">
|
||||||
<SelectField
|
<SelectField
|
||||||
value={year}
|
value={year}
|
||||||
onChange={handleYearChange}
|
onChange={handleYearChange}
|
||||||
className="w-auto h-[40px]"
|
className="w-full h-[40px]"
|
||||||
size="small"
|
size="small"
|
||||||
options={years.map(y => ({ value: y, label: y }))}
|
options={years.map(y => ({ value: y, label: y }))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center w-auto min-w-[72px]">
|
<div className="flex items-center w-[89px]">
|
||||||
<SelectField
|
<SelectField
|
||||||
value={quarter}
|
value={quarter}
|
||||||
onChange={handleQuarterChange}
|
onChange={handleQuarterChange}
|
||||||
className="w-auto h-[40px]"
|
className="w-full h-[40px]"
|
||||||
size="small"
|
size="small"
|
||||||
options={['All', 'Q1', 'Q2', 'Q3', 'Q4'].map(q => ({ value: q, label: q }))}
|
options={['All', 'Q1', 'Q2', 'Q3', 'Q4'].map(q => ({ value: q, label: q }))}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="h-10 px-3 xl:px-4 rounded-[6px] bg-[#F7F7F7] border border-[#C3C6CB] text-sm inline-flex items-center gap-2 hover:bg-gray-50 whitespace-nowrap font-medium text-[#232528]"
|
className="h-[40px] px-4 rounded-[6px] bg-[#F7F7F7] border border-[#C3C6CB] text-sm inline-flex items-center gap-2 hover:bg-gray-50 whitespace-nowrap font-medium text-[#232528]"
|
||||||
onClick={handleTriggerData}
|
onClick={handleTriggerData}
|
||||||
>
|
>
|
||||||
<img src={triggerIcon} alt="Trigger" className="h-5 w-5" />
|
<img src={triggerIcon} alt="Trigger" className="h-5 w-5" />
|
||||||
Calculate
|
Calculate
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="h-[40px] px-4 rounded-[6px] bg-[#F7F7F7] border border-[#C3C6CB] text-sm inline-flex items-center gap-2 hover:bg-gray-50 whitespace-nowrap font-medium text-[#232528]"
|
||||||
|
onClick={handleBaseYear}
|
||||||
|
>
|
||||||
|
<img src={triggerIcon} alt="Trigger" className="h-5 w-5" />
|
||||||
|
Base Year
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
className="h-10 px-3 xl:px-4 rounded-[6px] bg-[#F7F7F7] border border-[#C3C6CB] text-sm inline-flex items-center gap-2 hover:bg-gray-50 whitespace-nowrap"
|
className="h-10 px-3 xl:px-4 rounded-[6px] bg-[#F7F7F7] border border-[#C3C6CB] text-sm inline-flex items-center gap-2 hover:bg-gray-50 whitespace-nowrap"
|
||||||
@ -759,6 +801,7 @@ const handleSearchMonth = (e) => {
|
|||||||
<span className="hidden xl:inline font-medium text-[#232528]">Export CSV</span>
|
<span className="hidden xl:inline font-medium text-[#232528]">Export CSV</span>
|
||||||
<span className="xl:hidden font-medium text-[#232528]">Export</span>
|
<span className="xl:hidden font-medium text-[#232528]">Export</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{surveySubmitLoading || surveySubmitStatus || surveySubmitError ? (
|
{surveySubmitLoading || surveySubmitStatus || surveySubmitError ? (
|
||||||
|
|||||||
@ -9,8 +9,6 @@ const PublicContactForm = () => {
|
|||||||
|
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
userType: "establishment_user",
|
userType: "establishment_user",
|
||||||
establishmentName: "",
|
|
||||||
establishmentId: "",
|
|
||||||
email: "",
|
email: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -61,9 +59,6 @@ const PublicContactForm = () => {
|
|||||||
|
|
||||||
if (!data.userType) {
|
if (!data.userType) {
|
||||||
newErrors.userType = "Please select user type";
|
newErrors.userType = "Please select user type";
|
||||||
} else if (data.userType === 'establishment_user') {
|
|
||||||
if (!data.establishmentName.trim()) newErrors.establishmentName = "Required.";
|
|
||||||
if (!data.establishmentId.trim()) newErrors.establishmentId = "Required.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.email.trim()) newErrors.email = "Required.";
|
if (!data.email.trim()) newErrors.email = "Required.";
|
||||||
@ -94,8 +89,6 @@ const PublicContactForm = () => {
|
|||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
user_type: formData.userType,
|
user_type: formData.userType,
|
||||||
establishment_name: formData.establishmentName.trim(),
|
|
||||||
establishment_code: formData.establishmentId.trim(),
|
|
||||||
registered_email: formData.email.trim(),
|
registered_email: formData.email.trim(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -255,49 +248,7 @@ const PublicContactForm = () => {
|
|||||||
{success}
|
{success}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{formData.userType === 'establishment_user' && (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
|
||||||
Establishment Name <span className="text-red-500">*</span>
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
name="establishmentName"
|
|
||||||
value={formData.establishmentName}
|
|
||||||
onChange={handleChange}
|
|
||||||
className={`block w-full h-10 rounded-md border-2 ${
|
|
||||||
errors.establishmentName ? "border-red-500" : "border-[#92722A]"
|
|
||||||
} focus:border-[#92722A] focus:ring-0 px-4 text-sm`}
|
|
||||||
placeholder="Enter establishment name"
|
|
||||||
/>
|
|
||||||
{errors.establishmentName && (
|
|
||||||
<p className="text-xs text-red-600 mt-1">{errors.establishmentName}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-sm font-medium text-gray-700 mb-1">
|
|
||||||
Establishment ID <span className="text-red-500">*</span>
|
|
||||||
</label>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
name="establishmentId"
|
|
||||||
value={formData.establishmentId}
|
|
||||||
onChange={handleChange}
|
|
||||||
className={`block w-full h-10 rounded-md border-2 ${
|
|
||||||
errors.establishmentId ? "border-red-500" : "border-[#92722A]"
|
|
||||||
} focus:border-[#92722A] focus:ring-0 px-4 text-sm`}
|
|
||||||
placeholder="Enter establishment ID"
|
|
||||||
/>
|
|
||||||
{errors.establishmentId && (
|
|
||||||
<p className="text-xs text-red-600 mt-1">{errors.establishmentId}</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<InputField
|
<InputField
|
||||||
label="Registered Email"
|
label="Registered Email"
|
||||||
name="email"
|
name="email"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user