LMSN-188
LMS dapat upload dokumen TC corporate
This commit is contained in:
@@ -19,6 +19,10 @@ import HeaderBreadcrumbs from '../../components/HeaderBreadcrumbs';
|
||||
import CorporateTabNavigations from './CorporateTabNavigations';
|
||||
import { fCurrency } from '../../utils/formatNumber';
|
||||
import { ConfiguredCorporateContext } from '@/contexts/ConfiguredCorporateContext';
|
||||
import Iconify from '@/components/Iconify';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
import { makeFormData } from '@/utils/jsonToFormData';
|
||||
import { enqueueSnackbar } from 'notistack';
|
||||
|
||||
export default function Corporates() {
|
||||
const { themeStretch } = useSettings();
|
||||
@@ -29,11 +33,90 @@ export default function Corporates() {
|
||||
|
||||
useEffect(() => {
|
||||
setCorporate(configuredCorporateContext.currentCorporate);
|
||||
}, [configuredCorporateContext])
|
||||
getFilesDoc(corporate_id);
|
||||
}, [configuredCorporateContext, corporate_id])
|
||||
|
||||
const headStyle = {
|
||||
fontWeight: 'bold',
|
||||
};
|
||||
};
|
||||
// Upload Docs
|
||||
const fileDocsInput = useRef<HTMLInputElement>(null);
|
||||
const [fileDocs, setFileDocs] = useState([]);
|
||||
const [showAll, setShowAll] = useState(false);
|
||||
const [isActive, setIsActive] = useState(false);
|
||||
const handleDocsInputChange = (corporate_id) => (event) => {
|
||||
if(event.target.files[0] && corporate_id)
|
||||
{
|
||||
const updatedFiles = Array.from(event.target.files).map((file) => ({
|
||||
file
|
||||
}));
|
||||
submitUploadDocs(corporate_id, updatedFiles);
|
||||
}
|
||||
};
|
||||
function submitUploadDocs(corporate_id, files)
|
||||
{
|
||||
if(files.length > 0)
|
||||
{
|
||||
files.map((file, index) => {
|
||||
const formData = makeFormData(
|
||||
{
|
||||
corporate_id : corporate_id,
|
||||
result_files : file['file']
|
||||
}
|
||||
);
|
||||
axios
|
||||
.post('/add-files-doc', formData)
|
||||
.then((response) => {
|
||||
getFilesDoc(corporate_id);
|
||||
enqueueSnackbar(response.data.message, { variant: 'success' });
|
||||
})
|
||||
.catch((error) => {
|
||||
enqueueSnackbar(error.response.data.errors[0], { variant: 'error' });
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
function getFilesDoc(corporate_id)
|
||||
{
|
||||
axios
|
||||
.post('/get-files-doc',{corporate_id:corporate_id})
|
||||
.then((response) => {
|
||||
setFileDocs(response.data.data);
|
||||
if(response.data.data[0]['status_download'] == 1)
|
||||
{
|
||||
setIsActive(!isActive);
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsActive(isActive);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
enqueueSnackbar(error.response.data.errors[0], { variant: 'error' });
|
||||
});
|
||||
}
|
||||
|
||||
const toggleButton = () => {
|
||||
setIsActive(!isActive);
|
||||
let statusDownload = 0;
|
||||
if(!isActive)
|
||||
{
|
||||
statusDownload = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
statusDownload = 0;
|
||||
}
|
||||
axios
|
||||
.post('/update-status-files-doc', {status_download : statusDownload, corporate_id : corporate_id})
|
||||
.then((response) => {
|
||||
enqueueSnackbar(response.data.message, { variant: 'success' });
|
||||
})
|
||||
.catch((error) => {
|
||||
enqueueSnackbar(error.response.data.errors[0], { variant: 'error' });
|
||||
});
|
||||
};
|
||||
// End Upload Docs
|
||||
return (
|
||||
<Page title="Dashboard">
|
||||
|
||||
@@ -107,6 +190,114 @@ export default function Corporates() {
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
<Typography sx={{...headStyle, px:3, fontSize:'24px'}}>Docs (T&C)</Typography>
|
||||
|
||||
<Table>
|
||||
<TableBody>
|
||||
{fileDocs.length > 0 && (
|
||||
<TableRow>
|
||||
<TableCell sx={headStyle}>ASO members can download or not?</TableCell>
|
||||
<TableCell sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center'}}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
color={isActive ? "success" : "error"}
|
||||
size="small"
|
||||
onClick={toggleButton}
|
||||
>
|
||||
{isActive ? 'Active' : 'Inactive'}
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{fileDocs.slice(0, showAll ? fileDocs.length : 1).map((file, index) => (
|
||||
<TableRow key={index}>
|
||||
<TableCell sx={headStyle}>
|
||||
<a
|
||||
href={file.path} // Ganti URL sesuai kebutuhan Anda
|
||||
style={{ cursor: 'pointer', textDecoration: 'underline' }}
|
||||
target="_blank" // Untuk membuka tautan dalam tab baru
|
||||
>
|
||||
{file.original_name}
|
||||
</a>
|
||||
</TableCell>
|
||||
{!showAll && (
|
||||
<TableCell sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
|
||||
<Stack>
|
||||
<input
|
||||
type="file"
|
||||
id={`fileDocsID`}
|
||||
ref={fileDocsInput}
|
||||
style={{ display: 'none' }}
|
||||
onChange={(event) => {
|
||||
handleDocsInputChange(corporate_id)(event);
|
||||
}}
|
||||
accept="application/pdf"
|
||||
multiple
|
||||
/>
|
||||
|
||||
<Button
|
||||
variant="outlined"
|
||||
onClick={() => {
|
||||
fileDocsInput.current.click();
|
||||
}}
|
||||
sx={{ width: 'fit-content' }}
|
||||
>
|
||||
<Iconify icon="eva:plus-fill" />
|
||||
<span>Update Docs</span>
|
||||
</Button>
|
||||
</Stack>
|
||||
</TableCell>
|
||||
)}
|
||||
</TableRow>
|
||||
))}
|
||||
{!showAll && fileDocs.length > 1 && (
|
||||
<TableRow>
|
||||
<TableCell>
|
||||
<span onClick={() => setShowAll(true)} style={{ color: 'blue', cursor: 'pointer' }}>Lihat Semua Data</span>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{showAll && (
|
||||
<TableRow>
|
||||
<TableCell>
|
||||
<span onClick={() => setShowAll(false)} style={{ color: 'blue', cursor: 'pointer' }}>Sembunyikan Data</span>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{fileDocs.length <= 0 && (
|
||||
<TableRow>
|
||||
<TableCell sx={headStyle}>Please add a Terms & Conditions document</TableCell>
|
||||
<TableCell>
|
||||
<Stack>
|
||||
<input
|
||||
type="file"
|
||||
id={`fileDocsID`}
|
||||
ref={fileDocsInput}
|
||||
style={{ display: 'none' }}
|
||||
onChange={(event) => {
|
||||
handleDocsInputChange(corporate_id)(event);
|
||||
}}
|
||||
accept="application/pdf"
|
||||
// multiple
|
||||
/>
|
||||
<LoadingButton
|
||||
variant="outlined"
|
||||
onClick={() => {
|
||||
fileDocsInput.current.click();
|
||||
}}
|
||||
>
|
||||
<Iconify icon="eva:plus-fill" />
|
||||
<span>Add Docs</span>
|
||||
</LoadingButton>
|
||||
</Stack>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
|
||||
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
|
||||
Reference in New Issue
Block a user