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) {
|
||||
setFormData(props.selectedData);
|
||||
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();
|
||||
|
||||
// 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 baseURL = import.meta.env.VITE_API_SERVER || '';
|
||||
displayUrl = `${baseURL}/file-uploads/images/${encodeURIComponent(
|
||||
fileName
|
||||
)}${token ? `?token=${encodeURIComponent(token)}` : ''}`;
|
||||
}
|
||||
}
|
||||
|
||||
const fileName = props.selectedData.sparepart_foto.split('/').pop();
|
||||
const token = localStorage.getItem('token');
|
||||
const baseURL = import.meta.env.VITE_API_SERVER || '';
|
||||
const fullUrl = `${baseURL}/file-uploads/images/${encodeURIComponent(fileName)}${
|
||||
token ? `?token=${encodeURIComponent(token)}` : ''
|
||||
}`;
|
||||
|
||||
setFileList([
|
||||
{
|
||||
uid: '-1',
|
||||
name: fileName,
|
||||
status: 'done',
|
||||
url: fullUrl,
|
||||
url: displayUrl,
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
@@ -521,27 +534,6 @@ const DetailSparepart = (props) => {
|
||||
readOnly={props.readOnly}
|
||||
/>
|
||||
</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>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
Reference in New Issue
Block a user