Browse Source

feat(ui): add completion callback and i18n support to SliderPage

Introduces an `onComplete` callback to `SliderPage` to allow parent
components to control navigation logic after the slider process.
Additionally, implements internationalization for button labels within
the slider components to support multi-language interfaces.
master
mortezaei 5 days ago
parent
commit
eabf6df639
  1. 15
      src/app/intro/intro-client.tsx
  2. 26
      src/components/Componentes/slider-page.tsx

15
src/app/intro/intro-client.tsx

@ -125,6 +125,16 @@ export default function IntroClient() {
} }
}; };
const handleSliderComplete = useCallback(
(targetPath: string) => {
const destination = localizePath(targetPath, locale);
router.prefetch(destination);
setIsStepsOpen(false);
router.replace(destination);
},
[locale, router],
);
return ( return (
<> <>
<div className="pt-[max(12px,calc(var(--safe-top)+4px))]"> <div className="pt-[max(12px,calc(var(--safe-top)+4px))]">
@ -230,7 +240,10 @@ export default function IntroClient() {
onClose={handleCloseSteps} onClose={handleCloseSteps}
> >
{isStepsOpen && ( {isStepsOpen && (
<SliderPage onClose={handleCloseSteps} />
<SliderPage
onClose={handleCloseSteps}
onComplete={handleSliderComplete}
/>
)} )}
</SectionOverlayHost> </SectionOverlayHost>
</> </>

26
src/components/Componentes/slider-page.tsx

@ -26,9 +26,13 @@ const SLIDER_ANSWERS_STORAGE_KEY = "marriage-slider-answers";
export type SliderPageProps = { export type SliderPageProps = {
onClose?: () => void; onClose?: () => void;
onComplete?: (targetPath: string) => void;
}; };
export default function SliderPage({ onClose }: SliderPageProps = {}) {
export default function SliderPage({
onClose,
onComplete,
}: SliderPageProps = {}) {
const router = useRouter(); const router = useRouter();
const { locale } = useI18n(); const { locale } = useI18n();
const [activeSlide, setActiveSlide] = useState(0); const [activeSlide, setActiveSlide] = useState(0);
@ -114,7 +118,15 @@ export default function SliderPage({ onClose }: SliderPageProps = {}) {
window.localStorage.removeItem(SLIDER_ANSWERS_STORAGE_KEY); window.localStorage.removeItem(SLIDER_ANSWERS_STORAGE_KEY);
} }
router.replace(localizePath(getSubmitPath(freshProfile), locale));
const targetPath = getSubmitPath(freshProfile);
const localizedTarget = localizePath(targetPath, locale);
router.prefetch(localizedTarget);
if (onComplete) {
onComplete(targetPath);
} else {
router.replace(localizedTarget);
}
} catch (error) { } catch (error) {
console.error("Failed to complete onboarding:", error); console.error("Failed to complete onboarding:", error);
setSubmitError(t["Failed to update profile basic details. Please try again."] || "Failed to update profile basic details. Please try again."); setSubmitError(t["Failed to update profile basic details. Please try again."] || "Failed to update profile basic details. Please try again.");
@ -279,13 +291,14 @@ type SliderStepActionsProps = {
}; };
function SliderStepActions({ onBack, onNext }: SliderStepActionsProps) { function SliderStepActions({ onBack, onNext }: SliderStepActionsProps) {
const { dictionary: t } = useI18n();
return ( return (
<div className="flex items-center gap-3 [&>button]:flex-1"> <div className="flex items-center gap-3 [&>button]:flex-1">
<Button variant="outlined" arrowDirection="left" onClick={onBack}> <Button variant="outlined" arrowDirection="left" onClick={onBack}>
Back
{t["Back"] || t["back"] || "Back"}
</Button> </Button>
<Button arrowDirection="right" onClick={onNext}> <Button arrowDirection="right" onClick={onNext}>
Next
{t["Next"] || t["next"] || "Next"}
</Button> </Button>
</div> </div>
); );
@ -302,6 +315,7 @@ function SliderFinalActions({
onBack, onBack,
onFinish, onFinish,
}: SliderFinalActionsProps) { }: SliderFinalActionsProps) {
const { dictionary: t } = useI18n();
return ( return (
<div className="flex items-center gap-3 [&>button]:flex-1"> <div className="flex items-center gap-3 [&>button]:flex-1">
<Button <Button
@ -310,10 +324,10 @@ function SliderFinalActions({
disabled={isFinishing} disabled={isFinishing}
onClick={onBack} onClick={onBack}
> >
Back
{t["Back"] || t["back"] || "Back"}
</Button> </Button>
<Button disabled={isFinishing} isLoading={isFinishing} onClick={onFinish}> <Button disabled={isFinishing} isLoading={isFinishing} onClick={onFinish}>
Finish
{t["Finish"] || t["finish"] || "Finish"}
</Button> </Button>
</div> </div>
); );

Loading…
Cancel
Save