Skip to content

Commit

Permalink
changed asset list to product name in binding request.
Browse files Browse the repository at this point in the history
  • Loading branch information
sathishKarthikeyan committed Nov 13, 2024
1 parent 1b2f0b4 commit c92e0d3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
23 changes: 14 additions & 9 deletions frontend/src/pages/binding/create/[contractIfricId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'primereact/resources/primereact.min.css';
import 'primeicons/primeicons.css';
import "../../../styles/add-binding.css";
import { getCompanyDetailsById, verifyCompanyCertificate } from '../../../utility/auth';
import { getTemplateByName, getCompanyCertificate, getContractByType, getAssetByType, getAssetCertificateById, createBinding } from '@/utility/contract';
import { getTemplateByName, getCompanyCertificate, getContractByType, getAssetManagementData, getAssetCertificateById, createBinding } from '@/utility/contract';
import { Dropdown } from 'primereact/dropdown';
import moment from 'moment';
import Navbar from '@/components/navBar/navbar';
Expand Down Expand Up @@ -173,12 +173,17 @@ const CreateBinding: React.FC = () => {
setSelectedAssetProperties(selectedProperties);

// fetch assets of template type
const assetResponse = await getAssetByType(btoa(template.properties.asset_type.default));
if(assetResponse?.data) {
const options = assetResponse.data.map((value: { id: string }) => ({
label: value.id,
value: value.id
}));
const assetResponse = await getAssetManagementData(userData.company_ifric_id, template.properties.asset_type.default);
if(assetResponse) {
const options = assetResponse.map((value: Record<string,any>) => {
const productKey = Object.keys(value).find(key => key.includes('product_name'));
if(productKey && value[productKey]) {
return {
label: value[productKey].value,
value: value.id
}
}
});
setAssetOptions(options);
}
}
Expand Down Expand Up @@ -223,12 +228,12 @@ const CreateBinding: React.FC = () => {
}
}
} else {
setAssetVerified(null);
setAssetVerified(false);
toast.current?.show({ severity: 'warn', summary: 'Warn', detail: "Asset Certificate not found" });
}
}
} catch (error) {
setAssetVerified(null);
setAssetVerified(false);
console.error('Error fetching data:', error);
toast.current?.show({ severity: 'error', summary: 'Error', detail: 'Failed to load necessary data' });
}
Expand Down
30 changes: 29 additions & 1 deletion frontend/src/utility/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,32 @@ export const getAllContractByAssetType = async () => {
throw error;
}
}
};
};

export const getAssetManagementData = async (company_ifric_id: string, type: string) => {
try {
const result: Record<string,any> = [];
const response = await api.get(
`${BACKEND_API_URL}/asset/asset-management/${company_ifric_id}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});
if(response.data) {
response.data.forEach((value: Record<string,any>) => {
if(value.type === type) {
result.push(value);
}
})
}
return result;
} catch (error: any) {
if (error?.response && error?.response?.status === 401) {
updatePopupVisible(true);
return null;
} else {
throw error;
}
}
}

0 comments on commit c92e0d3

Please sign in to comment.