feat: enhance image URL handling in DetailSparepart component and remove status field display
This commit is contained in:
@@ -286,20 +286,33 @@ const DetailSparepart = (props) => {
|
|||||||
if (props.selectedData) {
|
if (props.selectedData) {
|
||||||
setFormData(props.selectedData);
|
setFormData(props.selectedData);
|
||||||
if (props.selectedData.sparepart_foto) {
|
if (props.selectedData.sparepart_foto) {
|
||||||
// Buat URL lengkap dengan token untuk file yang sudah ada
|
let displayUrl = props.selectedData.sparepart_foto;
|
||||||
|
|
||||||
|
// Jika URL bukan full URL (tidak mengandung http/https), bangun URL lokal
|
||||||
|
if (!props.selectedData.sparepart_foto.startsWith('http')) {
|
||||||
const fileName = props.selectedData.sparepart_foto.split('/').pop();
|
const fileName = props.selectedData.sparepart_foto.split('/').pop();
|
||||||
|
|
||||||
|
// Cek apakah ini file default
|
||||||
|
if (fileName === 'defaultSparepartImg.jpg') {
|
||||||
|
displayUrl = '/assets/defaultSparepartImg.jpg';
|
||||||
|
} else {
|
||||||
|
// Gunakan format file URL seperti di brandDevice
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
const baseURL = import.meta.env.VITE_API_SERVER || '';
|
const baseURL = import.meta.env.VITE_API_SERVER || '';
|
||||||
const fullUrl = `${baseURL}/file-uploads/images/${encodeURIComponent(fileName)}${
|
displayUrl = `${baseURL}/file-uploads/images/${encodeURIComponent(
|
||||||
token ? `?token=${encodeURIComponent(token)}` : ''
|
fileName
|
||||||
}`;
|
)}${token ? `?token=${encodeURIComponent(token)}` : ''}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileName = props.selectedData.sparepart_foto.split('/').pop();
|
||||||
|
|
||||||
setFileList([
|
setFileList([
|
||||||
{
|
{
|
||||||
uid: '-1',
|
uid: '-1',
|
||||||
name: fileName,
|
name: fileName,
|
||||||
status: 'done',
|
status: 'done',
|
||||||
url: fullUrl,
|
url: displayUrl,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
@@ -521,27 +534,6 @@ const DetailSparepart = (props) => {
|
|||||||
readOnly={props.readOnly}
|
readOnly={props.readOnly}
|
||||||
/>
|
/>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={12}>
|
|
||||||
<Text strong>Status</Text>
|
|
||||||
<Input
|
|
||||||
name="sparepart_stok"
|
|
||||||
value={
|
|
||||||
parseInt(formData.sparepart_qty) > 0
|
|
||||||
? 'Available'
|
|
||||||
: 'Not Available'
|
|
||||||
}
|
|
||||||
readOnly={true}
|
|
||||||
placeholder="Auto calculated"
|
|
||||||
style={{
|
|
||||||
backgroundColor: '#f5f5f5',
|
|
||||||
cursor: 'not-allowed',
|
|
||||||
color:
|
|
||||||
parseInt(formData.sparepart_qty) > 0
|
|
||||||
? '#52c41a'
|
|
||||||
: '#ff4d4f',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
</Row>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|||||||
Reference in New Issue
Block a user