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 { Box, Button, DialogActions, TextField } from "@mui/material";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
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 [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const { control, handleSubmit } = useForm({
|
const request = useRequest({ notificationSuccess: true });
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
handleSubmit,
|
||||||
|
formState: { errors },
|
||||||
|
} = useForm({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
expert_description: "",
|
expert_description: "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
const onSubmit = (data) => {
|
||||||
console.log(data);
|
|
||||||
setIsSubmitting(true);
|
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 (
|
return (
|
||||||
@@ -21,14 +39,27 @@ export default function ReferForm({ mutate, onClose }) {
|
|||||||
<Controller
|
<Controller
|
||||||
name="expert_description"
|
name="expert_description"
|
||||||
control={control}
|
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>
|
<DialogActions>
|
||||||
<Button onClick={onClose} variant="outlined" disabled={isSubmitting}>
|
<Button onClick={onClose} variant="outlined" disabled={isSubmitting}>
|
||||||
انصراف
|
انصراف
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="contained" onClick={handleSubmit(onSubmit)} disabled={isSubmitting}>
|
<Button variant="contained" onClick={handleSubmit(onSubmit)} disabled={isSubmitting}>
|
||||||
انجام عملیات
|
{isSubmitting ? "در حال ثبت..." : " انجام عملیات"}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export default function RenderActionForm({ type, rowData, mutate, onClose }) {
|
|||||||
function renderForm() {
|
function renderForm() {
|
||||||
switch (formType) {
|
switch (formType) {
|
||||||
case "refer_request_2":
|
case "refer_request_2":
|
||||||
return <ReferForm mutate={mutate} onClose={onClose} />;
|
return <ReferForm mutate={mutate} onClose={onClose} rowId={rowData.id} />;
|
||||||
case "reject_request_2":
|
case "reject_request_2":
|
||||||
return <RejectRequestForm mutate={mutate} onClose={onClose} />;
|
return <RejectRequestForm mutate={mutate} onClose={onClose} />;
|
||||||
case "reject_request_5":
|
case "reject_request_5":
|
||||||
|
|||||||
Reference in New Issue
Block a user