import moment from "jalali-moment"; import { toast } from "react-toastify"; export const numberToArStyle = (num) => num.toLocaleString("ar-AE"); export const isActiveURL = (link, name) => link === name; export const convertToJalali = (date) => { // Get the current Gregorian date const currentDate = date; // Convert the Gregorian date to Jalali date const jalaliDate = moment(currentDate).format("jYYYY/jM/jD"); // Get Jalali year, month, and day const jalaliYear = moment(jalaliDate, "jYYYY/jM/jD").jYear(); const jalaliMonth = moment(jalaliDate, "jYYYY/jM/jD").jMonth() + 1; // Note: jalali-moment months are zero-based const jalaliDay = moment(jalaliDate, "jYYYY/jM/jD").jDate(); return `${jalaliYear}/${jalaliMonth}/${jalaliDay}`; }; export const handleTwoLength = (value) => String(value).length === 1 ? `0${value}` : value; export const checkAllValues = (data) => { for (let key in data) { if (typeof data[key] === "object" && data[key] !== null) { if ("value" in data[key]) { if (!data[key].value) { return false; } } else { if (!checkAllValues(data[key])) { return false; } } } } return true; }; export const checkTimes = (arr) => { return arr.map((day) => { const hasMorningTime = day.morning_time.some((time) => time !== ""); const hasEveningTime = day.evening_time.some((time) => time !== ""); return hasMorningTime && hasEveningTime; }); }; export const uploadImage = async (event) => { let obj = { file: "", blob: "", }; const file = event.target.files[0]; if (file) { obj.file = file; const readFileAsDataURL = (file) => { return new Promise((resolve, reject) => { const reader = new FileReader(); reader.onload = () => resolve(reader.result); reader.onerror = (error) => reject(error); reader.readAsDataURL(file); }); }; try { obj.blob = await readFileAsDataURL(file); return obj; } catch (error) { console.error("Error reading file: ", error); throw error; } } else { throw new Error("No file selected"); } }; export const alert = (type, text, prop) => { toast[type](
پیغام{" "} {type === "error" ? "خطا" : type === "warning" ? "هشدار" : type === "info" ? "اعلام" : "موفقیت"}
{text}