Dodaj react-router-dom, mape tras i ProtectedRoute
Fundament migracji z useState(view) na prawdziwy routing: - react-router-dom 7 w zaleznosciach - BrowserRouter w main.tsx (nginx ma juz try_files, wiec czyste sciezki dzialaja) - routes.ts: centralna mapa adresow + helpery listingPath/mapPath/adminTabPath - ProtectedRoute z obsluga stanu loading z AuthProvider Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
// Centralna mapa adresów aplikacji. Jedyne źródło prawdy dla nawigacji —
|
||||
// komponenty korzystają z ROUTES zamiast trzymać identyfikatory widoków w stanie.
|
||||
export const ROUTES = {
|
||||
home: '/',
|
||||
buy: '/kupno',
|
||||
rent: '/wynajem',
|
||||
sell: '/jak-sprzedawac',
|
||||
valuation: '/wycena',
|
||||
priceHistory: '/historia-cen',
|
||||
districtRanking: '/ranking-dzielnic',
|
||||
negotiation: '/negocjacje',
|
||||
comparison: '/konto/porownanie',
|
||||
add: '/dodaj-ogloszenie',
|
||||
services: '/firmy-i-uslugi',
|
||||
guides: '/poradniki',
|
||||
guideBuying: '/poradniki/kupno-mieszkania',
|
||||
creditCalculator: '/kalkulator-zdolnosci',
|
||||
map: '/mapa',
|
||||
login: '/logowanie',
|
||||
account: '/konto',
|
||||
accountSearches: '/konto/wyszukiwania',
|
||||
accountPriceAlerts: '/konto/alerty-cenowe',
|
||||
accountMeetings: '/konto/spotkania',
|
||||
accountListings: '/konto/moje-oferty',
|
||||
accountSettings: '/konto/ustawienia',
|
||||
accountSecurity: '/konto/bezpieczenstwo',
|
||||
accountProfileEdit: '/konto/profil/edycja',
|
||||
accountPublicProfile: '/konto/profil',
|
||||
accountHelpContact: '/konto/pomoc',
|
||||
notifications: '/powiadomienia',
|
||||
favorites: '/ulubione',
|
||||
messages: '/wiadomosci',
|
||||
admin: '/admin',
|
||||
listingDetail: '/oferta/:id',
|
||||
} as const;
|
||||
|
||||
export type RoutePath = (typeof ROUTES)[keyof typeof ROUTES];
|
||||
|
||||
// Szczegóły oferty: identyfikator trafia do adresu, nie do stanu Reacta.
|
||||
export function listingPath(id: number): string {
|
||||
return `/oferta/${id}`;
|
||||
}
|
||||
|
||||
// Negocjacje dotyczą konkretnej oferty — bez identyfikatora pokazujemy pierwszą z listy.
|
||||
export function negotiationPath(offerId?: number | null): string {
|
||||
return offerId ? `${ROUTES.negotiation}/${offerId}` : ROUTES.negotiation;
|
||||
}
|
||||
|
||||
// Mapa: miasto i typ oferty jako parametry zapytania, dzięki czemu wynik da się udostępnić.
|
||||
export function mapPath(city?: string, offerType?: 'SALE' | 'RENT'): string {
|
||||
const params = new URLSearchParams();
|
||||
if (city) {
|
||||
params.set('miasto', city);
|
||||
}
|
||||
if (offerType === 'RENT') {
|
||||
params.set('typ', 'wynajem');
|
||||
}
|
||||
const query = params.toString();
|
||||
return query ? `${ROUTES.map}?${query}` : ROUTES.map;
|
||||
}
|
||||
|
||||
// Zakładki panelu administratora jako podścieżki /admin/*.
|
||||
export const ADMIN_TAB_PATHS = {
|
||||
dashboard: '',
|
||||
listings: 'ogloszenia',
|
||||
users: 'uzytkownicy',
|
||||
messages: 'wiadomosci',
|
||||
reports: 'zgloszenia',
|
||||
payments: 'platnosci',
|
||||
stats: 'statystyki',
|
||||
settings: 'ustawienia',
|
||||
moderation: 'weryfikacja',
|
||||
categories: 'kategorie',
|
||||
locations: 'lokalizacje',
|
||||
promotions: 'promocje',
|
||||
forbiddenWords: 'zakazane-slowa',
|
||||
leads: 'leady',
|
||||
campaigns: 'kampanie',
|
||||
mailConfig: 'konfiguracja-wysylki',
|
||||
} as const;
|
||||
|
||||
export type AdminTabKey = keyof typeof ADMIN_TAB_PATHS;
|
||||
|
||||
export function adminTabPath(tab: AdminTabKey): string {
|
||||
const segment = ADMIN_TAB_PATHS[tab];
|
||||
return segment ? `${ROUTES.admin}/${segment}` : ROUTES.admin;
|
||||
}
|
||||
|
||||
export const ADMIN_PATH_TO_TAB = Object.entries(ADMIN_TAB_PATHS).reduce<Record<string, AdminTabKey>>(
|
||||
(acc, [tab, segment]) => {
|
||||
acc[segment] = tab as AdminTabKey;
|
||||
return acc;
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
// Trasy dostępne wyłącznie po zalogowaniu (bramka w ProtectedRoute).
|
||||
export const PROTECTED_PATHS: string[] = [
|
||||
ROUTES.add,
|
||||
ROUTES.account,
|
||||
ROUTES.accountSearches,
|
||||
ROUTES.accountPriceAlerts,
|
||||
ROUTES.accountMeetings,
|
||||
ROUTES.accountListings,
|
||||
ROUTES.accountSettings,
|
||||
ROUTES.accountSecurity,
|
||||
ROUTES.accountProfileEdit,
|
||||
ROUTES.accountPublicProfile,
|
||||
ROUTES.accountHelpContact,
|
||||
ROUTES.notifications,
|
||||
ROUTES.favorites,
|
||||
ROUTES.messages,
|
||||
ROUTES.comparison,
|
||||
];
|
||||
Reference in New Issue
Block a user