|
|
|
|
@@ -127,13 +127,12 @@ export default function OrganizationsForm({ isEdit, currentOrganizations }: Prop
|
|
|
|
|
village_id: currentOrganizations?.village_id || '',
|
|
|
|
|
postal_code: currentOrganizations?.postal_code || '',
|
|
|
|
|
description: currentOrganizations?.description || '',
|
|
|
|
|
corporate_id_partner: currentOrganizations?.corporate_id_partner || [],
|
|
|
|
|
}),
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
[currentOrganizations]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
console.log('defaultValues', defaultValues);
|
|
|
|
|
|
|
|
|
|
function StatusLabel({ value }: { value: boolean }) {
|
|
|
|
|
return (
|
|
|
|
|
<Chip
|
|
|
|
|
@@ -217,6 +216,8 @@ export default function OrganizationsForm({ isEdit, currentOrganizations }: Prop
|
|
|
|
|
formData.append('postal_code', data.postal_code);
|
|
|
|
|
formData.append('description', data.description);
|
|
|
|
|
|
|
|
|
|
formData.append('corporate_id_partner', data.corporate_id_partner);
|
|
|
|
|
|
|
|
|
|
if (!isEdit) {
|
|
|
|
|
console.log('formData', formData);
|
|
|
|
|
const response = await axios.post('/organizations', formData);
|
|
|
|
|
@@ -256,6 +257,15 @@ export default function OrganizationsForm({ isEdit, currentOrganizations }: Prop
|
|
|
|
|
const [district, setDistrict] = useState<any>([]);
|
|
|
|
|
const [village, setVillage] = useState<any>([]);
|
|
|
|
|
|
|
|
|
|
const [corporate_id_partner, setCorporateIdPartner] = useState<any>([]);
|
|
|
|
|
const [selectedCorporatID, setSelectedCorporateID] = useState<any>([]);
|
|
|
|
|
|
|
|
|
|
const handleSelectChange = (event, selectedOptions:any) => {
|
|
|
|
|
const selectedValues = selectedOptions.map(option => option.value);
|
|
|
|
|
setSelectedCorporateID(selectedValues);
|
|
|
|
|
setValue('corporate_id_partner', selectedCorporatID)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
axios.get('/province').then((res) => {
|
|
|
|
|
setProvince(res.data.data.map((item: any) => ({ value: item.id, label: item.name })));
|
|
|
|
|
@@ -304,6 +314,27 @@ export default function OrganizationsForm({ isEdit, currentOrganizations }: Prop
|
|
|
|
|
}
|
|
|
|
|
}, [values.province_id, values.city_id, values.district_id, values.village_id]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
axios.get('/corporates').then((res) => {
|
|
|
|
|
setCorporateIdPartner(res.data.data.map((item: any) => ({ value: item.id, label: item.name })));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const loadCorporateIdPartner = async () => {
|
|
|
|
|
if (values.corporate_id_partner == currentOrganizations?.corporate_id_partner){
|
|
|
|
|
const res = await axios.get('/corporates');
|
|
|
|
|
setCorporateIdPartner(res.data.data.map((item: any) => ({ value: item.id, label: item.name })));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (values.corporate_id_partner) {
|
|
|
|
|
loadCorporateIdPartner();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(corporate_id_partner, 'test');
|
|
|
|
|
|
|
|
|
|
}, [values.corporate_id_partner])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const findValueProvince = province.find(
|
|
|
|
|
(item: any) => item.value === currentOrganizations?.province_id
|
|
|
|
|
);
|
|
|
|
|
@@ -315,6 +346,10 @@ export default function OrganizationsForm({ isEdit, currentOrganizations }: Prop
|
|
|
|
|
(item: any) => item.value === currentOrganizations?.village_id
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const findValueCorporate = selectedCorporatID.find(
|
|
|
|
|
(item: any) => item.value === currentOrganizations?.corporate_id_partner
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<FormProvider methods={methods} onSubmit={handleSubmit(onSubmit)}>
|
|
|
|
|
<Stack spacing={3}>
|
|
|
|
|
@@ -450,6 +485,8 @@ export default function OrganizationsForm({ isEdit, currentOrganizations }: Prop
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Grid item xs={12} md={4}>
|
|
|
|
|
<LabelStyle>Kode Pos</LabelStyle>
|
|
|
|
|
<RHFTextField name="postal_code" placeholder="Tuliskan Kode Pos" />
|
|
|
|
|
@@ -462,6 +499,28 @@ export default function OrganizationsForm({ isEdit, currentOrganizations }: Prop
|
|
|
|
|
<LabelStyle>Longitude</LabelStyle>
|
|
|
|
|
<RHFTextField name="lng" placeholder="Tuliskan Longitude" />
|
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
|
|
<Grid item xs={12}>
|
|
|
|
|
<LabelStyle>Rekanan</LabelStyle>
|
|
|
|
|
<Controller
|
|
|
|
|
name="corporate_id_partner"
|
|
|
|
|
control={control}
|
|
|
|
|
render={({ field: { onChange, value } }) => (
|
|
|
|
|
<Autocomplete
|
|
|
|
|
id="combo-box-demo"
|
|
|
|
|
options={corporate_id_partner}
|
|
|
|
|
getOptionLabel={(option) => option.label}
|
|
|
|
|
value={corporate_id_partner.filter(option => selectedCorporatID.includes(option.value))}
|
|
|
|
|
onChange={handleSelectChange}
|
|
|
|
|
multiple // Enable multiple selections
|
|
|
|
|
renderInput={(params) => (
|
|
|
|
|
<TextField {...params} label="Corporate" variant="outlined" fullWidth />
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
|
|
<Grid item xs={12}>
|
|
|
|
|
<LabelStyle>Deskripsi</LabelStyle>
|
|
|
|
|
<RHFEditor name="description" placeholder="Tuliskan Deskripsi" />
|
|
|
|
|
|