Skip to content

Commit 4b1e60e

Browse files
authored
Merge pull request #279 from map-of-pi/feature/navbar-alerts
Approved (1).
2 parents 453652c + 9fc0718 commit 4b1e60e

File tree

10 files changed

+102
-66
lines changed

10 files changed

+102
-66
lines changed

context/AppContextProvider.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ interface IAppContextProps {
2626
autoLoginUser: ()=> void;
2727
isSigningInUser: boolean;
2828
reload: boolean;
29+
alertMessage: string | null;
30+
showAlert: (message: string) => void;
2931
setReload: React.Dispatch<SetStateAction<boolean>>;
3032
}
3133

@@ -36,6 +38,8 @@ const initialState: IAppContextProps = {
3638
autoLoginUser: ()=> {},
3739
isSigningInUser: false,
3840
reload: false,
41+
alertMessage: null,
42+
showAlert: () => {},
3943
setReload: () => {},
4044
};
4145

@@ -51,6 +55,15 @@ const AppContextProvider = ({ children }: AppContextProviderProps) => {
5155
const [isSigningInUser, setIsSigningInUser] = useState(false);
5256
const [reload, setReload] = useState(false);
5357

58+
const [alertMessage, setAlertMessage] = useState<string | null>(null);
59+
60+
const showAlert = (message: string) => {
61+
setAlertMessage(message);
62+
setTimeout(() => {
63+
setAlertMessage(null); // Clear alert after 5 seconds
64+
}, 5000);
65+
};
66+
5467
const registerUser = async () => {
5568
logger.info('Initializing Pi SDK for user registration.');
5669
await Pi.init({ version: '2.0', sandbox: process.env.NODE_ENV === 'development' });
@@ -116,7 +129,7 @@ const AppContextProvider = ({ children }: AppContextProviderProps) => {
116129
}, []);
117130

118131
return (
119-
<AppContext.Provider value={{ currentUser, setCurrentUser, registerUser, autoLoginUser, isSigningInUser, reload, setReload }}>
132+
<AppContext.Provider value={{ currentUser, setCurrentUser, registerUser, autoLoginUser, isSigningInUser, reload, setReload, showAlert, alertMessage }}>
120133
{children}
121134
</AppContext.Provider>
122135
);

messages/en-GB.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
},
3131
"CONTACT_MAP_OF_PI": "Contact Map of Pi",
3232
"VALIDATION": {
33-
"SUCCESSFUL_PREFERENCES_SUBMISSION": "User Preferences update successful",
34-
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "User Preferences update failed"
33+
"SUCCESSFUL_PREFERENCES_SUBMISSION": "Preferences successful",
34+
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "Error saving preferences"
3535
}
3636
},
3737
"SCREEN": {
@@ -62,7 +62,8 @@
6262
"SELLER_SELL_CENTER": "Set Sell Centre",
6363
"VALIDATION": {
6464
"EMAIL_VALIDATION": "Please enter a valid email address",
65-
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Seller Registration submitted successfully",
65+
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Registration successful",
66+
"FAILED_REGISTRATION_SUBMISSION": "Error saving registration",
6667
"REGISTRATION_FAILED_USER_NOT_AUTHENTICATED": "Registration failed because user is not authenticated",
6768
"UNINITIALIZED_SELL_CENTER": "Please set your Sell Centre"
6869
}
@@ -246,7 +247,7 @@
246247
"SEARCH_CENTER_SUCCESS_MESSAGE": "Your Search Centre has been saved successfully"
247248
}
248249
},
249-
"LOADING_SCREEN_MESSAGE": "Loading data...",
250+
"LOADING_SCREEN_MESSAGE": "Loading ...",
250251
"VALIDATION": {
251252
"SUBMISSION_FAILED_USER_NOT_AUTHENTICATED": "Submission failed because user is not authenticated",
252253
"UNEXPECTED_ERROR_MESSAGE": "Unexpected error occurred"

messages/en.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
},
3131
"CONTACT_MAP_OF_PI": "Contact Map of Pi",
3232
"VALIDATION": {
33-
"SUCCESSFUL_PREFERENCES_SUBMISSION": "User Preferences update successful",
34-
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "User Preferences update failed"
33+
"SUCCESSFUL_PREFERENCES_SUBMISSION": "Preferences successful",
34+
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "Error saving preferences"
3535
}
3636
},
3737
"SCREEN": {
@@ -62,7 +62,8 @@
6262
"SELLER_SELL_CENTER": "Set Sell Center",
6363
"VALIDATION": {
6464
"EMAIL_VALIDATION": "Please enter a valid email address",
65-
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Seller Registration submitted successfully",
65+
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Registration successful",
66+
"FAILED_REGISTRATION_SUBMISSION": "Error saving registration",
6667
"REGISTRATION_FAILED_USER_NOT_AUTHENTICATED": "Registration failed because user is not authenticated",
6768
"UNINITIALIZED_SELL_CENTER": "Please set your Sell Center"
6869
}
@@ -235,7 +236,7 @@
235236
"SELL_CENTER_SUCCESS_MESSAGE": "Your Sell Center has been saved successfully"
236237
}
237238
},
238-
"LOADING_SCREEN_MESSAGE": "Loading data...",
239+
"LOADING_SCREEN_MESSAGE": "Loading ...",
239240
"VALIDATION": {
240241
"SUBMISSION_FAILED_USER_NOT_AUTHENTICATED": "Submission failed because user is not authenticated",
241242
"UNEXPECTED_ERROR_MESSAGE": "Unexpected error occurred"

messages/es.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
},
3131
"CONTACT_MAP_OF_PI": "Contactar a Map of Pi",
3232
"VALIDATION": {
33-
"SUCCESSFUL_PREFERENCES_SUBMISSION": "Actualización de preferencias del usuario exitosa",
34-
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "La actualización de las preferencias del usuario falló"
33+
"SUCCESSFUL_PREFERENCES_SUBMISSION": "Preferencias guardadas con éxito",
34+
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "Error al guardar las preferencias"
3535
}
3636
},
3737
"SCREEN": {
@@ -62,7 +62,8 @@
6262
"SELLER_SELL_CENTER": "Establecer Centro de Venta",
6363
"VALIDATION": {
6464
"EMAIL_VALIDATION": "Por favor, ingresa una dirección de correo electrónico válida",
65-
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Registro de vendedor enviado con éxito",
65+
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Registro exitoso",
66+
"FAILED_REGISTRATION_SUBMISSION": "Error al guardar el registro",
6667
"REGISTRATION_FAILED_USER_NOT_AUTHENTICATED": "El registro falló porque el usuario no está autenticado",
6768
"UNINITIALIZED_SELL_CENTER": "Por favor, establezca su Centro de Venta"
6869
}
@@ -233,7 +234,7 @@
233234
"SEARCH_CENTER_SUCCESS_MESSAGE": "Tu centro de búsqueda se ha guardado correctamente"
234235
}
235236
},
236-
"LOADING_SCREEN_MESSAGE": "Cargando datos...",
237+
"LOADING_SCREEN_MESSAGE": "Cargando ...",
237238
"VALIDATION": {
238239
"SUBMISSION_FAILED_USER_NOT_AUTHENTICATED": "El envío falló porque el usuario no está autenticado",
239240
"UNEXPECTED_ERROR_MESSAGE": "Ocurrió un error inesperado"

messages/ewe-BJ.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
},
3131
"CONTACT_MAP_OF_PI": "Wò Map of Pi me",
3232
"VALIDATION": {
33-
"SUCCESSFUL_PREFERENCES_SUBMISSION": "Nuŋlɔdodoawo ƒe se se yia ɖe asi me",
34-
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "Nusrɔkɔdɔ togbɔna mewɔna o"
33+
"SUCCESSFUL_PREFERENCES_SUBMISSION": "Etsɔnyɛ nufiala nɔe o",
34+
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "Nufiala menɔa wo nɛ gbɔna o"
3535
}
3636
},
3737
"SCREEN": {
@@ -62,7 +62,8 @@
6262
"SELLER_SELL_CENTER": "Nàƒé Wòkpɔ̃nɔnyewo",
6363
"VALIDATION": {
6464
"EMAIL_VALIDATION": "Metsɔ ema aɖeke wɔna le ŋgɔ le eme",
65-
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Nyatakɔɖu nàtsoɖe tɔ wòɖé yèna nyuie",
65+
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Nukplɔla nɔa gbedodo",
66+
"FAILED_REGISTRATION_SUBMISSION": "Kplɔla menɔa wo nɛ gbɔna o",
6667
"REGISTRATION_FAILED_USER_NOT_AUTHENTICATED": "Nɔviɖewɔwɔ na mi kplɔ nɛ ƒe viwo nɔ anyi nyɔnu ƒe ŋu nɔ anyi",
6768
"UNINITIALIZED_SELL_CENTER": "Mɛnya ɖe gbe na wo trɔtrɔ wo fiawo tso me"
6869
}
@@ -233,7 +234,7 @@
233234
"SEARCH_CENTER_SUCCESS_MESSAGE": "Nye dzi tsɔtɔ wɔm o"
234235
}
235236
},
236-
"LOADING_SCREEN_MESSAGE": "Ɣe siwo...",
237+
"LOADING_SCREEN_MESSAGE": "Gɔme ɖa ...",
237238
"VALIDATION": {
238239
"SUBMISSION_FAILED_USER_NOT_AUTHENTICATED": "Nɔvia míaɖu abe nu wò ye mele wònu o le fifiawo nyo",
239240
"UNEXPECTED_ERROR_MESSAGE": "Nuxlɔ̃sia na mi ɖe mɔ o"

messages/hau-NG.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
},
3131
"CONTACT_MAP_OF_PI": "Tuntubi Map of Pi",
3232
"VALIDATION": {
33-
"SUCCESSFUL_PREFERENCES_SUBMISSION": "Sabunta zaɓuɓɓukan mai amfani ya yi nasara",
34-
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "Sabuntawar zaɓuɓɓukan mai amfani ta gaza"
33+
"SUCCESSFUL_PREFERENCES_SUBMISSION": "Zaɓuɓɓuka sun yi nasara",
34+
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "Kuskure wajen adana zaɓuɓɓuka"
3535
}
3636
},
3737
"SCREEN": {
@@ -62,7 +62,8 @@
6262
"SELLER_SELL_CENTER": "Saita Cibiyar Sayarwa",
6363
"VALIDATION": {
6464
"EMAIL_VALIDATION": "Don Allah shigar da ingantaccen adireshin imel",
65-
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Rijista ta sayarwa ta samu nasara",
65+
"SUCCESSFUL_REGISTRATION_SUBMISSION": "Rajista ta yi nasara",
66+
"FAILED_REGISTRATION_SUBMISSION": "Kuskure wajen adana rajista",
6667
"REGISTRATION_FAILED_USER_NOT_AUTHENTICATED": "Rijista ta gaza saboda mai amfani ba a tantance shi ba",
6768
"UNINITIALIZED_SELL_CENTER": "Da fatan za ku saita cibiyar sayarwarku"
6869
}
@@ -232,7 +233,7 @@
232233
"SEARCH_CENTER_SUCCESS_MESSAGE": "An adana Cibiyar Bincike ɗinku cikin nasara"
233234
}
234235
},
235-
"LOADING_SCREEN_MESSAGE": "Ana ɗaukar bayanai...",
236+
"LOADING_SCREEN_MESSAGE": "Ana loda ...",
236237
"VALIDATION": {
237238
"SUBMISSION_FAILED_USER_NOT_AUTHENTICATED": "Aika ya kasa saboda mai amfani ba a tabbatar da shi ba",
238239
"UNEXPECTED_ERROR_MESSAGE": "An samu kuskure da ba a zata ba"

messages/ko.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
},
3131
"CONTACT_MAP_OF_PI": "Map of Pi에 문의",
3232
"VALIDATION": {
33-
"SUCCESSFUL_PREFERENCES_SUBMISSION": "사용자 환경 설정 업데이트 성공",
34-
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "사용자 환경 설정 업데이트 실패"
33+
"SUCCESSFUL_PREFERENCES_SUBMISSION": "환경 설정이 성공적으로 완료되었습니다",
34+
"UNSUCCESSFUL_PREFERENCES_SUBMISSION": "환경 설정 저장 중 오류 발생"
3535
}
3636
},
3737
"SCREEN": {
@@ -62,7 +62,8 @@
6262
"SELLER_SELL_CENTER": "판매 센터 설정",
6363
"VALIDATION": {
6464
"EMAIL_VALIDATION": "유효한 이메일 주소를 입력하세요",
65-
"SUCCESSFUL_REGISTRATION_SUBMISSION": "판매자 등록이 성공적으로 제출되었습니다",
65+
"SUCCESSFUL_REGISTRATION_SUBMISSION": "등록이 성공적으로 완료되었습니다",
66+
"FAILED_REGISTRATION_SUBMISSION": "등록 저장 중 오류 발생",
6667
"REGISTRATION_FAILED_USER_NOT_AUTHENTICATED": "사용자가 인증되지 않아 등록에 실패했습니다",
6768
"UNINITIALIZED_SELL_CENTER": "판매 센터를 설정해주세요"
6869
}
@@ -233,7 +234,7 @@
233234
"SEARCH_CENTER_SUCCESS_MESSAGE": "검색 센터가 성공적으로 저장되었습니다"
234235
}
235236
},
236-
"LOADING_SCREEN_MESSAGE": "데이터 로딩 중...",
237+
"LOADING_SCREEN_MESSAGE": "로딩 중 ...",
237238
"VALIDATION": {
238239
"SUBMISSION_FAILED_USER_NOT_AUTHENTICATED": "제출이 실패했습니다; 사용자가 인증되지 않았습니다",
239240
"UNEXPECTED_ERROR_MESSAGE": "예기치 않은 오류가 발생했습니다"

src/app/[locale]/seller/registration/page.tsx

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { useTranslations } from 'next-intl';
44
import Link from 'next/link';
55
import { useRouter } from 'next/navigation';
66
import { useState, useEffect, useContext } from 'react';
7-
import { toast } from 'react-toastify';
87

98
import TrustMeter from '@/components/shared/Review/TrustMeter';
109
import { OutlineBtn, Button } from '@/components/shared/Forms/Buttons/Buttons';
@@ -33,7 +32,7 @@ const SellerRegistrationForm = () => {
3332
const t = useTranslations();
3433
const placeholderSeller = itemData.seller;
3534

36-
const { currentUser, autoLoginUser } = useContext(AppContext);
35+
const { currentUser, autoLoginUser, showAlert } = useContext(AppContext);
3736

3837
type IFormData = {
3938
sellerName: string;
@@ -217,7 +216,8 @@ const SellerRegistrationForm = () => {
217216
// Check if user is authenticated and form is valid
218217
if (!currentUser) {
219218
logger.warn('Form submission failed: User not authenticated.');
220-
return toast.error(t('SHARED.VALIDATION.SUBMISSION_FAILED_USER_NOT_AUTHENTICATED'));
219+
showAlert(t('SHARED.VALIDATION.SUBMISSION_FAILED_USER_NOT_AUTHENTICATED'));
220+
return;
221221
}
222222

223223
preFilledFields.forEach(({ fieldName, preFilledTextKey }) => {
@@ -246,14 +246,18 @@ const SellerRegistrationForm = () => {
246246
setDbSeller(data.seller);
247247
setIsSaveEnabled(false);
248248
logger.info('Seller registration saved successfully:', { data });
249-
toast.success(t('SCREEN.SELLER_REGISTRATION.VALIDATION.SUCCESSFUL_REGISTRATION_SUBMISSION'));
249+
showAlert(t('SCREEN.SELLER_REGISTRATION.VALIDATION.SUCCESSFUL_REGISTRATION_SUBMISSION'));
250250

251251
// Fetch updated user settings
252252
const updatedUserSettings = await fetchUserSettings();
253253
setDbUserSettings(updatedUserSettings);
254254
}
255-
} catch (error) {
256-
logger.error('Error saving seller registration:', { error });
255+
} catch (error: any) {
256+
logger.error('Error saving seller registration:', {
257+
message: error.message,
258+
stack: error.stack
259+
});
260+
showAlert(t('SCREEN.SELLER_REGISTRATION.VALIDATION.FAILED_REGISTRATION_SUBMISSION'));
257261
}
258262
};
259263

src/components/shared/navbar/Navbar.tsx

+45-32
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { usePathname, useRouter } from 'next/navigation';
66

77
import { useContext, useEffect, useState } from 'react';
88
import { FiMenu } from 'react-icons/fi';
9+
import { ImSpinner2 } from 'react-icons/im';
910
import { IoMdArrowBack, IoMdClose } from 'react-icons/io';
1011
import { MdHome } from 'react-icons/md';
1112

@@ -22,7 +23,7 @@ function Navbar() {
2223
const [sidebarToggle, setSidebarToggle] = useState(false);
2324
const [isHomePage, setIsHomePage] = useState(true);
2425

25-
const {isSigningInUser, reload} = useContext(AppContext)
26+
const {isSigningInUser, reload, alertMessage} = useContext(AppContext)
2627

2728
// check if the current page is the homepage
2829
useEffect(() => {
@@ -47,46 +48,58 @@ function Navbar() {
4748

4849
return (
4950
<>
50-
<div
51-
className={`w-full h-[76.19px] z-500 px-[16px] py-[5px] bg-primary fixed top-0 left-0 right-0 `}>
51+
<div className="w-full h-[76.19px] z-500 px-[16px] py-[5px] bg-primary fixed top-0 left-0 right-0">
5252
<div className="text-center text-secondary text-[1.3rem] whitespace-nowrap">
53-
{ isSigningInUser || reload ? t('SHARED.LOADING_SCREEN_MESSAGE'): "Map of Pi"}
53+
{/* Display alert message with spinner if present, otherwise display 'Map of Pi' */}
54+
{alertMessage ? (
55+
<div className="alert-message flex items-center justify-center text-[1rem]"> {/* Adjust font size */}
56+
<ImSpinner2 className="animate-spin mr-2 ml-1" /> {/* Spinner Icon */}
57+
{alertMessage}
58+
</div>
59+
) : (
60+
isSigningInUser || reload ? (
61+
<div className="flex items-center justify-center">
62+
<ImSpinner2 className="animate-spin mr-2 ml-1" /> {/* Spinner Icon */}
63+
{t('SHARED.LOADING_SCREEN_MESSAGE')}
64+
</div>
65+
) : (
66+
"Map of Pi"
67+
)
68+
)}
5469
</div>
55-
<div
56-
className="flex justify-between">
70+
<div className="flex justify-between">
5771
<div className={`${styles.nav_item} ${isHomePage && 'disabled'}`}>
5872
<Link href="/" onClick={handleBackBtn}>
5973
<IoMdArrowBack size={26} className={`${isHomePage ? 'text-tertiary' : 'text-secondary'}`} />
6074
</Link>
6175
</div>
6276

63-
<div className={`${styles.nav_item} ${isHomePage && 'disabled'}`}>
64-
<Link href="/">
65-
<MdHome size={24} className={`${isHomePage ? 'text-tertiary' : 'text-secondary'}`} />
66-
</Link>
67-
</div>
77+
<div className={`${styles.nav_item} ${isHomePage && 'disabled'}`}>
78+
<Link href="/">
79+
<MdHome size={24} className={`${isHomePage ? 'text-tertiary' : 'text-secondary'}`} />
80+
</Link>
81+
</div>
82+
6883
<div className={`${styles.nav_item}`}>
69-
<Link
70-
href=""
71-
onClick={(e) => {
72-
if (isSigningInUser) {
73-
e.preventDefault();
74-
} else {
75-
handleMenu();
76-
}
77-
}}
78-
>
79-
{sidebarToggle && !isSigningInUser ? (
80-
<IoMdClose size={24} className="text-secondary" />
81-
) : (
82-
<FiMenu
83-
size={24}
84-
className={`${
85-
isSigningInUser ? 'text-tertiary cursor-not-allowed' : 'text-secondary'
86-
}`}
87-
/>
88-
)}
89-
</Link>
84+
<Link
85+
href=""
86+
onClick={(e) => {
87+
if (isSigningInUser) {
88+
e.preventDefault();
89+
} else {
90+
handleMenu();
91+
}
92+
}}
93+
>
94+
{sidebarToggle && !isSigningInUser ? (
95+
<IoMdClose size={24} className="text-secondary" />
96+
) : (
97+
<FiMenu
98+
size={24}
99+
className={`${isSigningInUser ? 'text-tertiary cursor-not-allowed' : 'text-secondary'}`}
100+
/>
101+
)}
102+
</Link>
90103
</div>
91104
</div>
92105
</div>

0 commit comments

Comments
 (0)