implemented referal action for privacy office
This commit is contained in:
@@ -1,19 +1,37 @@
|
||||
import { PRIVACY_ADMIN_ACTION_API } from "@/core/utils/routes";
|
||||
import useRequest from "@/lib/hooks/useRequest";
|
||||
import { Box, Button, DialogActions, TextField } from "@mui/material";
|
||||
import { useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
|
||||
export default function ReferForm({ mutate, onClose }) {
|
||||
export default function ReferForm({ mutate, onClose, rowId }) {
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const { control, handleSubmit } = useForm({
|
||||
const request = useRequest({ notificationSuccess: true });
|
||||
|
||||
const {
|
||||
control,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
defaultValues: {
|
||||
expert_description: "",
|
||||
},
|
||||
});
|
||||
|
||||
const onSubmit = (data) => {
|
||||
console.log(data);
|
||||
setIsSubmitting(true);
|
||||
mutate();
|
||||
try {
|
||||
request(`${PRIVACY_ADMIN_ACTION_API}/refer_request/${rowId}`, "post", {
|
||||
data,
|
||||
}).then(() => {
|
||||
onClose();
|
||||
mutate();
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -21,14 +39,27 @@ export default function ReferForm({ mutate, onClose }) {
|
||||
<Controller
|
||||
name="expert_description"
|
||||
control={control}
|
||||
render={({ field }) => <TextField {...field} fullWidth multiline minRows={3} label="توضیحات" />}
|
||||
rules={{
|
||||
required: "توضیحات الزامی است",
|
||||
}}
|
||||
render={({ field }) => (
|
||||
<TextField
|
||||
{...field}
|
||||
error={!!errors.expert_description}
|
||||
helperText={errors.expert_description?.message}
|
||||
fullWidth
|
||||
multiline
|
||||
minRows={3}
|
||||
label="توضیحات"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<DialogActions>
|
||||
<Button onClick={onClose} variant="outlined" disabled={isSubmitting}>
|
||||
انصراف
|
||||
</Button>
|
||||
<Button variant="contained" onClick={handleSubmit(onSubmit)} disabled={isSubmitting}>
|
||||
انجام عملیات
|
||||
{isSubmitting ? "در حال ثبت..." : " انجام عملیات"}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Box>
|
||||
|
||||
@@ -12,7 +12,7 @@ export default function RenderActionForm({ type, rowData, mutate, onClose }) {
|
||||
function renderForm() {
|
||||
switch (formType) {
|
||||
case "refer_request_2":
|
||||
return <ReferForm mutate={mutate} onClose={onClose} />;
|
||||
return <ReferForm mutate={mutate} onClose={onClose} rowId={rowData.id} />;
|
||||
case "reject_request_2":
|
||||
return <RejectRequestForm mutate={mutate} onClose={onClose} />;
|
||||
case "reject_request_5":
|
||||
|
||||
Reference in New Issue
Block a user