page add panel/doctor role agent && save data crop img && upload img && just roles agent can access panel && save data doctor && add field phone number && remove two tab
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import moment from "jalali-moment";
|
||||
|
||||
export const dateToTimestamp = (date) => {
|
||||
const gregorianMoment = moment(date, "jYYYY/jM/jD").locale("fa");
|
||||
const unixTimestamp = gregorianMoment.valueOf();
|
||||
return unixTimestamp / 1000;
|
||||
};
|
||||
|
||||
export const transformData = (data) => {
|
||||
return {
|
||||
name: data.name.value,
|
||||
activity_time: dateToTimestamp(data.time_work.value),
|
||||
doctor_mobile_number: data.phone.value,
|
||||
degree: data.degree.value,
|
||||
specialty: [Number(data.expertise.value)],
|
||||
info: data.description.value,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
import ArrowLeftPA from "@/components/icons/ArrowLeftPA";
|
||||
import { checkAllValues } from "@/helper";
|
||||
import { request } from "@/services/response";
|
||||
import { Button } from "@mui/material";
|
||||
import { useState } from "react";
|
||||
import { transformData } from "./function";
|
||||
import { defaultState } from "../../defaultState";
|
||||
|
||||
function SendReq({ img, data, resetData }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const saveData = (img) => {
|
||||
let transformed = transformData(data);
|
||||
|
||||
if (img) {
|
||||
transformed.image = [img];
|
||||
}
|
||||
|
||||
request
|
||||
.postDoctor(transformed)
|
||||
.then(() => {
|
||||
resetData();
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
const saveImg = () => {
|
||||
setLoading(true);
|
||||
if (img) {
|
||||
request
|
||||
.postImageUpload(img.file)
|
||||
.then((res) => {
|
||||
const imgId = res.fid[0].value;
|
||||
saveData(imgId);
|
||||
})
|
||||
.catch((err) => {
|
||||
setLoading(false);
|
||||
});
|
||||
} else {
|
||||
saveData();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mt-[40px] w-full flex justify-end">
|
||||
<Button
|
||||
className="!w-full md:!w-fit !shadow-none !rounded-[4px] !gap-[4px] !text-[#EFEFEF] !text-[14px] md:!text-[16px] !font-medium"
|
||||
// onClick={() => setValue((prev) => prev + 1)}
|
||||
disabled={!checkAllValues(data)}
|
||||
variant="contained"
|
||||
onClick={saveImg}
|
||||
loading={loading}
|
||||
>
|
||||
<p className={loading ? "opacity-0" : ""}>ثبت اطلاعات</p>
|
||||
<div className={!checkAllValues(data) ? "opacity-40" : "opacity-100"}>
|
||||
<ArrowLeftPA />
|
||||
</div>
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default SendReq;
|
||||
Reference in New Issue
Block a user