Skip to content

Commit

Permalink
feat(build): done changes for build
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalEsMagico committed Dec 14, 2023
1 parent 5ef0fdc commit 1beb8bf
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 47 deletions.
2 changes: 0 additions & 2 deletions src/app/sign-up/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -168,7 +167,6 @@ const Signup = () => {
userData={{
...generalDetailsData,
...bankDetailsData,
email,
logoUrl,
}}
onClose={() => setIsOpen(false)}
Expand Down
4 changes: 2 additions & 2 deletions src/components/myAccount/UserEditSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type PropType = {
providerId: string;
user: userType;
setShowEditSection: (val: boolean) => void;
getUserProfile: () => void;
getUserProfile: (arg: string) => void;
};

const UserEditSection = ({
Expand Down Expand Up @@ -123,7 +123,7 @@ const UserEditSection = ({
try {
await updateProviderProfileDetails(providerId, formData);
setShowEditSection(false);
getUserProfile();
getUserProfile(providerId);
toast.success('data updated successfully', {
draggable: false,
});
Expand Down
7 changes: 4 additions & 3 deletions src/components/signupComponent/UserDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type DataType = {
branchName: string;
accNo: string;
IFSC: string;
email: string;
email?: string;
GSTnumber: string;
PANnumber: string;
logoUrl: string;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
87 changes: 47 additions & 40 deletions src/context/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit 1beb8bf

Please sign in to comment.