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 triggerIcon from '@/assets/trigger.png';
|
||||
import { getManufacturingIndex, getManufacturingMonthlyOverview, autoSubmitSurvey, getManufacturingIndexFiltered } from '@/services/manufacturingIndex/ManufacturingIndex';
|
||||
import apiClient from '@/services/api/apiClient';
|
||||
|
||||
// Import popup components
|
||||
import ManufacturingTotal from './ManufacturingIndexPopup/ManufacturingTotal';
|
||||
@ -27,6 +28,7 @@ import ISIC2Digit from './ManufacturingIndexPopup/ISIC2Digit';
|
||||
import ISIC3Digit from './ManufacturingIndexPopup/ISIC3Digit';
|
||||
import ISIC4Digit from './ManufacturingIndexPopup/ISIC4Digit';
|
||||
|
||||
|
||||
// Custom components
|
||||
const SelectField = (props) => (
|
||||
<BaseSelectField
|
||||
@ -62,6 +64,9 @@ const ManufacturingIndex = () => {
|
||||
const [surveySubmitLoading, setSurveySubmitLoading] = useState(false);
|
||||
const [surveySubmitStatus, setSurveySubmitStatus] = useState('');
|
||||
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 [refreshKey, setRefreshKey] = useState(0);
|
||||
|
||||
@ -132,9 +137,7 @@ const ManufacturingIndex = () => {
|
||||
}
|
||||
|
||||
// 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
|
||||
const formattedData = dataArray.map((item, index) => {
|
||||
@ -335,6 +338,36 @@ const handleSearchMonth = (e) => {
|
||||
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 () => {
|
||||
setError(null);
|
||||
setSurveySubmitStatus('');
|
||||
@ -709,9 +742,10 @@ const handleSearchMonth = (e) => {
|
||||
Coverage: Manufacturing (ISIC C)
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div className="flex items-center gap-3 w-full sm:w-auto">
|
||||
<div className="flex-1 sm:flex-none w-40">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-[180px]">
|
||||
<div className="relative">
|
||||
<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" />
|
||||
@ -725,31 +759,39 @@ const handleSearchMonth = (e) => {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center w-auto min-w-[88px]">
|
||||
<div className="flex items-center w-[99px]">
|
||||
<SelectField
|
||||
value={year}
|
||||
onChange={handleYearChange}
|
||||
className="w-auto h-[40px]"
|
||||
className="w-full h-[40px]"
|
||||
size="small"
|
||||
options={years.map(y => ({ value: y, label: y }))}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center w-auto min-w-[72px]">
|
||||
<div className="flex items-center w-[89px]">
|
||||
<SelectField
|
||||
value={quarter}
|
||||
onChange={handleQuarterChange}
|
||||
className="w-auto h-[40px]"
|
||||
className="w-full h-[40px]"
|
||||
size="small"
|
||||
options={['All', 'Q1', 'Q2', 'Q3', 'Q4'].map(q => ({ value: q, label: q }))}
|
||||
/>
|
||||
</div>
|
||||
<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}
|
||||
>
|
||||
<img src={triggerIcon} alt="Trigger" className="h-5 w-5" />
|
||||
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
|
||||
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="xl:hidden font-medium text-[#232528]">Export</span>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{surveySubmitLoading || surveySubmitStatus || surveySubmitError ? (
|
||||
|
||||
@ -9,8 +9,6 @@ const PublicContactForm = () => {
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
userType: "establishment_user",
|
||||
establishmentName: "",
|
||||
establishmentId: "",
|
||||
email: "",
|
||||
});
|
||||
|
||||
@ -61,9 +59,6 @@ const PublicContactForm = () => {
|
||||
|
||||
if (!data.userType) {
|
||||
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.";
|
||||
@ -94,8 +89,6 @@ const PublicContactForm = () => {
|
||||
try {
|
||||
const payload = {
|
||||
user_type: formData.userType,
|
||||
establishment_name: formData.establishmentName.trim(),
|
||||
establishment_code: formData.establishmentId.trim(),
|
||||
registered_email: formData.email.trim(),
|
||||
};
|
||||
|
||||
@ -255,49 +248,7 @@ const PublicContactForm = () => {
|
||||
{success}
|
||||
</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
|
||||
label="Registered Email"
|
||||
name="email"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user