Add calender validations
parent
04fd60d6bc
commit
d44677a034
|
|
@ -206,9 +206,9 @@ export default function HomeScreen() {
|
|||
setRefreshing(true);
|
||||
startSpin();
|
||||
|
||||
await dispatch(clearUser());
|
||||
await dispatch(getUserDetails()).unwrap();
|
||||
await dispatch(getPaymentSummary()).unwrap();
|
||||
// await dispatch(clearUser());
|
||||
await dispatch(getUserDetails());
|
||||
await dispatch(getPaymentSummary());
|
||||
|
||||
console.log("Manual refresh complete");
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ const BatteryDetails = () => {
|
|||
const model = data?.batteries[0]?.battery_model ?? "---";
|
||||
const batteryId = data?.batteries[0]?.battery_id ?? "---";
|
||||
const bmsId = data?.batteries[0]?.bms_id ?? "---";
|
||||
const warrantyStartDate = data?.batteries[0]?.warranty_start_date ?? "---";
|
||||
const warrantyEndDate = data?.batteries[0]?.warranty_end_date ?? "---";
|
||||
const vimId = data?.batteries[0]?.vim_id ?? "---";
|
||||
const serialNumber = data?.batteries[0]?.serial_no ?? "---";
|
||||
const chargerUid = data?.batteries[0]?.charger_uid ?? "---";
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@ import {
|
|||
KeyboardAvoidingView,
|
||||
Platform,
|
||||
ActivityIndicator,
|
||||
Keyboard,
|
||||
} from "react-native";
|
||||
import { Dropdown } from "react-native-element-dropdown";
|
||||
import { DateTimePickerAndroid } from "@react-native-community/datetimepicker";
|
||||
import * as ImagePicker from "expo-image-picker";
|
||||
import { Formik, FormikHelpers } from "formik";
|
||||
import { FastField, Formik, FormikHelpers } from "formik";
|
||||
import * as Yup from "yup";
|
||||
import ChevronRight from "../../assets/icons/chevron_rightside.svg";
|
||||
import AddPhoto from "../../assets/icons/add_photo_alternate.svg";
|
||||
|
|
@ -23,11 +24,13 @@ import IssueSelectorModal from "@/components/service/IssueSelectorModal";
|
|||
import { uploadImage } from "@/utils/User";
|
||||
import api from "@/services/axiosClient";
|
||||
import { useSnackbar } from "@/contexts/Snackbar";
|
||||
import { BASE_URL } from "@/constants/config";
|
||||
import { BASE_URL, SERVICE } from "@/constants/config";
|
||||
import { Overlay } from "@/components/common/Overlay";
|
||||
import CrossIcon from "@/assets/icons/close_white.svg";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import CalendarIcon from "@/assets/icons/calendar.svg";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "@/store";
|
||||
|
||||
interface FormValues {
|
||||
serviceType: string | null;
|
||||
|
|
@ -58,6 +61,8 @@ export default function ServiceFormScreen(): JSX.Element {
|
|||
const [isFocus, setIsFocus] = useState<boolean>(false);
|
||||
const [isIssueSelectorVisible, setIssueSelectorVisible] = useState(false);
|
||||
|
||||
const { data } = useSelector((state: RootState) => state.user);
|
||||
|
||||
const [issues, setIssues] = useState<Issue[]>([]);
|
||||
const [isLoadingIssues, setIsLoadingIssues] = useState(false);
|
||||
const { showSnackbar } = useSnackbar();
|
||||
|
|
@ -66,6 +71,37 @@ export default function ServiceFormScreen(): JSX.Element {
|
|||
setIssueSelectorVisible(!isIssueSelectorVisible);
|
||||
}
|
||||
|
||||
function checkSixMonthsCondition(warrantyStartDate: string | undefined) {
|
||||
if (warrantyStartDate) {
|
||||
const startDate = new Date(warrantyStartDate);
|
||||
|
||||
const monthsLater = new Date(startDate);
|
||||
monthsLater.setMonth(
|
||||
monthsLater.getMonth() + SERVICE.ENABLE_REGULAR_SERVICE_AFTER_IN_MONTHS
|
||||
);
|
||||
|
||||
const today = new Date();
|
||||
|
||||
if (today >= monthsLater) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const warrantyStartDay = data?.batteries[0]?.warranty_start_date;
|
||||
const isAfterSixMonths = checkSixMonthsCondition(warrantyStartDay);
|
||||
|
||||
const dropdownData = isAfterSixMonths
|
||||
? [
|
||||
{ label: "Regular", value: "Regular" },
|
||||
{ label: "On-demand", value: "On-demand" },
|
||||
]
|
||||
: [{ label: "On-demand", value: "On-demand" }];
|
||||
|
||||
const fetchIssues = async () => {
|
||||
try {
|
||||
setIsLoadingIssues(true);
|
||||
|
|
@ -111,13 +147,9 @@ export default function ServiceFormScreen(): JSX.Element {
|
|||
}
|
||||
};
|
||||
|
||||
const showPicker = (
|
||||
currentDate: Date | null,
|
||||
setFieldValue: (field: string, value: any) => void
|
||||
) => {
|
||||
const now = currentDate || new Date();
|
||||
const showPicker = (setFieldValue: (field: string, value: any) => void) => {
|
||||
const now = new Date();
|
||||
|
||||
// First, show the date picker
|
||||
DateTimePickerAndroid.open({
|
||||
value: now,
|
||||
mode: "date",
|
||||
|
|
@ -147,6 +179,16 @@ export default function ServiceFormScreen(): JSX.Element {
|
|||
showSnackbar(`${t("service.select-valid-time")}`, "error");
|
||||
return;
|
||||
}
|
||||
|
||||
//(10AM - 5PM)
|
||||
const hours = combinedDate.getHours();
|
||||
if (hours < 10 || hours >= 17) {
|
||||
showSnackbar(
|
||||
t("service.time-must-be-between-10-and-5"),
|
||||
"error"
|
||||
);
|
||||
return;
|
||||
}
|
||||
setFieldValue("date", combinedDate);
|
||||
}
|
||||
},
|
||||
|
|
@ -203,6 +245,7 @@ export default function ServiceFormScreen(): JSX.Element {
|
|||
values: FormValues,
|
||||
actions: FormikHelpers<FormValues>
|
||||
) => {
|
||||
Keyboard.dismiss();
|
||||
try {
|
||||
const uploadedPhotoUrls: string[] = [];
|
||||
for (const uri of values.photos) {
|
||||
|
|
@ -271,10 +314,7 @@ export default function ServiceFormScreen(): JSX.Element {
|
|||
selectedTextStyle={styles.selectedTextStyle}
|
||||
inputSearchStyle={styles.inputSearchStyle}
|
||||
iconStyle={styles.iconStyle}
|
||||
data={[
|
||||
{ label: "Regular", value: "Regular" },
|
||||
{ label: "On-demand", value: "On-demand" },
|
||||
]}
|
||||
data={dropdownData}
|
||||
maxHeight={200}
|
||||
labelField="label"
|
||||
valueField="value"
|
||||
|
|
@ -315,13 +355,9 @@ export default function ServiceFormScreen(): JSX.Element {
|
|||
styles.issueTextDisabled,
|
||||
]}
|
||||
>
|
||||
{isLoadingIssues ? (
|
||||
<ActivityIndicator />
|
||||
) : (
|
||||
getSelectedIssuesText(values.issues)
|
||||
)}
|
||||
{getSelectedIssuesText(values.issues)}
|
||||
</Text>
|
||||
<ChevronRight />
|
||||
{isLoadingIssues ? <ActivityIndicator /> : <ChevronRight />}
|
||||
</TouchableOpacity>
|
||||
{touched.issues && errors.issues && (
|
||||
<Text style={styles.error}>{errors.issues}</Text>
|
||||
|
|
@ -330,11 +366,11 @@ export default function ServiceFormScreen(): JSX.Element {
|
|||
|
||||
<View style={{ marginTop: 8 }}>
|
||||
<Text style={styles.label}>
|
||||
{t("service.select-datetime")}{" "}
|
||||
{t("service.select-datetime")}
|
||||
<Text style={styles.required}>*</Text>
|
||||
</Text>
|
||||
<TouchableOpacity
|
||||
onPress={() => showPicker(values.date, setFieldValue)}
|
||||
onPress={() => showPicker(setFieldValue)}
|
||||
style={styles.inputBoxDate}
|
||||
>
|
||||
<Text style={styles.dateText}>
|
||||
|
|
|
|||
|
|
@ -68,6 +68,10 @@ export const useTabConfig = () => {
|
|||
];
|
||||
};
|
||||
|
||||
export const SERVICE = {
|
||||
ENABLE_REGULAR_SERVICE_AFTER_IN_MONTHS: 6,
|
||||
};
|
||||
|
||||
export const MESSAGES = {
|
||||
AUTHENTICATION: {
|
||||
INVALID_TOKEN: "Invalid Token",
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@
|
|||
"service-type": "Service Type",
|
||||
"issue": "Issue",
|
||||
"select-issue": "Select Issue",
|
||||
"select-datetime": "Select Date and Time",
|
||||
"select-datetime": "Select Date and Time (10AM - 5PM)",
|
||||
"select": "-Select-",
|
||||
"add-photos": "Add photos",
|
||||
"supported-formats": "Supported formats include JPG, JPEG and PNG.",
|
||||
|
|
@ -131,7 +131,8 @@
|
|||
"service-request-success": "Service request submitted successfully",
|
||||
"something-went-wrong": "Something went wrong!",
|
||||
"select-valid-time": "Select valid time",
|
||||
"words": "words"
|
||||
"words": "words",
|
||||
"time-must-be-between-10-and-5": "Select a time between 10 AM – 5 PM."
|
||||
},
|
||||
"battery": {
|
||||
"battery-and-warranty": "My Battery and Warranty",
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@
|
|||
"service-type": "सेवा प्रकार",
|
||||
"issue": "समस्या",
|
||||
"select-issue": "समस्या का चयन करें",
|
||||
"select-datetime": "दिनांक और समय का चयन करें",
|
||||
"select-datetime": "दिनांक और समय (10AM - 5PM) का चयन करें",
|
||||
"select": "-चुनें-",
|
||||
"add-photos": "फ़ोटो जोड़ें",
|
||||
"supported-formats": "समर्थित प्रारूपों में JPG, JPEG और PNG शामिल हैं।",
|
||||
|
|
@ -131,7 +131,8 @@
|
|||
"service-request-success": "सेवा अनुरोध सफलतापूर्वक सबमिट किया गया",
|
||||
"something-went-wrong": "कुछ गलत हो गया!",
|
||||
"words": "शब्द",
|
||||
"select-valid-time": "सही समय चुनें"
|
||||
"select-valid-time": "सही समय चुनें",
|
||||
"time-must-be-between-10-and-5": "समय सुबह 10:00 बजे से शाम 5:00 बजे के बीच चुनें।"
|
||||
},
|
||||
"battery": {
|
||||
"battery-and-warranty": "मेरी बैटरी और वारंटी",
|
||||
|
|
|
|||
Loading…
Reference in New Issue