This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Child Component (Custom Input + Auto Focus) | |
| // “forwardRef lets a parent component directly access a child’s DOM element or method through a ref, | |
| // which is not possible with normal props.” | |
| import React, { forwardRef } from "react"; | |
| const TextInput = forwardRef((props, ref) => { | |
| return <input ref={ref} {...props} />; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const regexValidators = { | |
| fullName: z | |
| .string() | |
| .regex(/^[a-zA-Z0-9_]{3,16}$/, "Only letters, numbers & underscore"), | |
| phone: z | |
| .string() | |
| .regex(/^\+91\d{10}$/, "Phone must be +91XXXXXXXXXX"), | |
| strongPassword: z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import api from "./api"; // your axios instance | |
| export const checkEmailExists = async (email) => { | |
| try { | |
| const res = await api.post("/auth/check-email", { email }); | |
| return res.data.exists; // true / false | |
| } catch (e) { | |
| return false; | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Important Notes | |
| queryFn: ApiServices.getLandingPage(query) // ❌ executes immediately | |
| queryFn: () => ApiServices.getLandingPage(query) // ✅ pass a function. / queryFn must be a function that returns a Promise | |
| // React Query will call it internally, handle await, and track isLoading, isError, data automatically | |
| // mutate fn | |
| mutationFn: async (payload) => { | |
| const res = await ApiServices.registerUserWithRoles(payload); // Or with extra logic: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // apis/APIs.js | |
| class ApiServices { | |
| async updateProfile(data) { | |
| try { | |
| const res = await api.put("/user/update-profile", data); | |
| return res?.data; | |
| } catch (error) { | |
| throw error.response?.data || error; | |
| } finally { | |
| console.log("updateProfile: FINALLY executed"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useQuery, useSuspenseQuery } from "@tanstack/react-query"; | |
| import ApiServices from "../../apis/APIs.js"; | |
| // api has try, catch, finally | |
| class ApiServices { | |
| async getLandingPage(query = {}) { | |
| try { | |
| const response = await api.get(`/user/dashboard`, { | |
| params: query, | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="otp-inputs"> | |
| <input type="text" class="text-box no-arrow otp" id="otp1" maxlength="1" | |
| onkeydown="otpFocusHandler(event, 1)" autocomplete="off" /> | |
| <input type="text" class="text-box no-arrow otp" id="otp2" maxlength="1" | |
| onkeydown="otpFocusHandler(event, 2)" autocomplete="off" /> | |
| <input type="text" class="text-box no-arrow otp" id="otp3" maxlength="1" | |
| onkeydown="otpFocusHandler(event, 3)" autocomplete="off" /> | |
| <input type="text" class="text-box no-arrow otp" id="otp4" maxlength="1" | |
| onkeydown="otpFocusHandler(event, 4)" autocomplete="off" /> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // services | |
| // Verify OTP & issue tokens | |
| export async function verifyOtp(mobile) { | |
| // Find or create user | |
| let user = await prisma.user.findUnique({ where: { mobile } }); | |
| // ✅ If not found, create user | |
| // if (!user) { | |
| // user = await prisma.user.create({ | |
| // data: { | |
| // mobile, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // formatDate helper functions | |
| const formatDate = (dateString, format = "dd/MM/yyyy") => { | |
| if (!dateString) return ""; // Handle empty date | |
| const date = new Date(dateString); | |
| if (isNaN(date.getTime())) return "Invalid Date"; // Check if date is valid | |
| const day = String(date.getDate()).padStart(2, "0"); | |
| const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero-based | |
| const year = date.getFullYear(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Backend Controller | |
| export const viewAdvisorListing = async (req, res) => { | |
| const { | |
| advId, | |
| page = 1, | |
| limit = 150, | |
| startDate, | |
| endDate, | |
| policyNo, | |
| insuredName, |
NewerOlder