diff --git a/src/app/sign-up/page.tsx b/src/app/sign-up/page.tsx index 02a6671..bc5713e 100644 --- a/src/app/sign-up/page.tsx +++ b/src/app/sign-up/page.tsx @@ -68,7 +68,6 @@ const initialBankDetailsData = (): BankDetailsType => { }; const Signup = () => { - const email = localStorage?.getItem('userEmailId') || ''; const [logoUrl, setLogoUrl] = useState(''); const [step, setStep] = useState(1); const [isOpen, setIsOpen] = useState(false); @@ -168,7 +167,6 @@ const Signup = () => { userData={{ ...generalDetailsData, ...bankDetailsData, - email, logoUrl, }} onClose={() => setIsOpen(false)} diff --git a/src/components/myAccount/UserEditSection.tsx b/src/components/myAccount/UserEditSection.tsx index a0f8591..4fc2454 100644 --- a/src/components/myAccount/UserEditSection.tsx +++ b/src/components/myAccount/UserEditSection.tsx @@ -64,7 +64,7 @@ type PropType = { providerId: string; user: userType; setShowEditSection: (val: boolean) => void; - getUserProfile: () => void; + getUserProfile: (arg: string) => void; }; const UserEditSection = ({ @@ -123,7 +123,7 @@ const UserEditSection = ({ try { await updateProviderProfileDetails(providerId, formData); setShowEditSection(false); - getUserProfile(); + getUserProfile(providerId); toast.success('data updated successfully', { draggable: false, }); diff --git a/src/components/signupComponent/UserDetailsModal.tsx b/src/components/signupComponent/UserDetailsModal.tsx index c3951af..1dc5512 100644 --- a/src/components/signupComponent/UserDetailsModal.tsx +++ b/src/components/signupComponent/UserDetailsModal.tsx @@ -23,7 +23,7 @@ type DataType = { branchName: string; accNo: string; IFSC: string; - email: string; + email?: string; GSTnumber: string; PANnumber: string; logoUrl: string; @@ -57,7 +57,7 @@ const convertToFormData = (data: DataType) => { const userFormData = new FormData(); userFormData.append('name', data?.name); - userFormData.append('email', data?.email); + if (data?.email) userFormData.append('email', data?.email); userFormData.append('logo', data?.orgLogo); userFormData.append('orgName', data?.orgName); userFormData.append('password', data?.password); @@ -83,10 +83,11 @@ const UserDetailsModal = ({ userData, handleStep, onClose }: PropType) => { const { handleSetProviderId } = useAuthContext(); const handleContinue = () => { + const email = localStorage?.getItem('userEmailId') || ''; (async () => { setIsDisabled(true); // convert object into form data - const userFormData = convertToFormData(userData); + const userFormData = convertToFormData({ ...userData, email }); try { const data = await userSignup(userFormData); handleSetProviderId(data?.providerId); diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx index 89a90cd..8fb1a51 100644 --- a/src/context/AuthContext.tsx +++ b/src/context/AuthContext.tsx @@ -35,7 +35,7 @@ const userProfileInitData = { type AuthContextType = { providerId: string; userProfileData: userType; - handleUserProfile: () => void; + handleUserProfile: (id: string) => void; handleSetProviderId: (id: string) => void; setActiveComponent: (arg: string) => void; activeComponent: string; @@ -69,67 +69,74 @@ const AuthProvider = createContext<AuthContextType>({ }); const AuthContext = ({ children }: { children: React.ReactElement }) => { - const id = localStorage.getItem('3cpToken') || ''; - const [providerId, setProviderId] = useState(id); + const [providerId, setProviderId] = useState(''); const [activeComponent, setActiveComponent] = useState<string>('ACCEPTED'); const [userProfileData, setUserProfileDate] = useState(userProfileInitData); const [fetchData, setFetchData] = useState(true); const [courseList, setCourseList] = useState<CourseType[]>([]); const router = useRouter(); - const handleCourseData = useCallback(async () => { - try { - const data = await getCourseByProviderId(providerId); - setCourseList(data); - setFetchData(false); - } catch (error) { - // Handle any errors that occur during the API call - setTimeout(() => { - // eslint-disable-next-line no-console - console.error('API call error:', error); - toast.error('something went wrong', { - draggable: false, - }); - router.push('/error/DataNotFound'); - }, 5000); - } - }, [providerId, router]); + const handleCourseData = useCallback( + async (id: string) => { + try { + const data = await getCourseByProviderId(id); + setCourseList(data); + setFetchData(false); + } catch (error) { + // Handle any errors that occur during the API call + setTimeout(() => { + // eslint-disable-next-line no-console + console.error('API call error:', error); + toast.error('something went wrong', { + draggable: false, + }); + router.push('/error/DataNotFound'); + }, 5000); + } + }, + [router] + ); - const handleUserProfile = useCallback(async () => { - try { - const data = await getProviderProfileDetails(providerId); - setUserProfileDate(data); - handleCourseData(); - } catch (error) { - // Handle any errors that occur during the API call - setTimeout(() => { - // eslint-disable-next-line no-console - console.error('API call error:', error); - toast.error('something went wrong', { - draggable: false, - }); - router.push('/error/DataNotFound'); - }, 5000); - } - }, [providerId, handleCourseData, router]); + const handleUserProfile = useCallback( + async (id: string) => { + try { + const data = await getProviderProfileDetails(id); + setUserProfileDate(data); + handleCourseData(id); + } catch (error) { + // Handle any errors that occur during the API call + setTimeout(() => { + // eslint-disable-next-line no-console + console.error('API call error:', error); + toast.error('something went wrong', { + draggable: false, + }); + router.push('/error/DataNotFound'); + }, 5000); + } + }, + [handleCourseData, router] + ); const handleSetProviderId = (id: string) => { setProviderId(id); }; useEffect(() => { - if (!providerId) { + const id = localStorage.getItem('3cpToken') || ''; + if (!id) { router.push('/login'); return; } else { - handleUserProfile(); + setProviderId(id); + handleUserProfile(id); router.push('my-courses'); } }, [router, providerId, handleUserProfile]); useEffect(() => { if (fetchData && providerId) { - handleCourseData(); + handleCourseData(providerId); } }, [fetchData, handleCourseData, providerId]);