website refactor
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import type { ProfileLeaguesPageDto } from '@/lib/page-queries/page-queries/ProfileLeaguesPageQuery';
|
||||
import { ProfileLeaguesPresenter } from '@/lib/presenters/ProfileLeaguesPresenter';
|
||||
import { ProfileLeaguesTemplate } from '@/templates/ProfileLeaguesTemplate';
|
||||
|
||||
interface ProfileLeaguesPageClientProps {
|
||||
pageDto: ProfileLeaguesPageDto;
|
||||
}
|
||||
|
||||
export function ProfileLeaguesPageClient({ pageDto }: ProfileLeaguesPageClientProps) {
|
||||
// Convert Page DTO to ViewData using Presenter
|
||||
const viewData = ProfileLeaguesPresenter.toViewData(pageDto);
|
||||
|
||||
// Render Template with ViewData
|
||||
return <ProfileLeaguesTemplate viewData={viewData} />;
|
||||
}
|
||||
@@ -1,23 +1,24 @@
|
||||
import { notFound } from 'next/navigation';
|
||||
import { ProfileLeaguesPageQuery } from '@/lib/page-queries/page-queries/ProfileLeaguesPageQuery';
|
||||
import { ProfileLeaguesPageClient } from './ProfileLeaguesPageClient';
|
||||
import { ProfileLeaguesTemplate } from '@/templates/ProfileLeaguesTemplate';
|
||||
|
||||
export default async function ProfileLeaguesPage() {
|
||||
const result = await ProfileLeaguesPageQuery.execute();
|
||||
|
||||
switch (result.status) {
|
||||
case 'notFound':
|
||||
if (result.isErr()) {
|
||||
const error = result.getError();
|
||||
|
||||
if (error === 'notFound') {
|
||||
notFound();
|
||||
case 'redirect':
|
||||
// Note: In Next.js, redirect would be imported from next/navigation
|
||||
// For now, we'll handle this case by returning notFound
|
||||
// In a full implementation, you'd use: redirect(result.to);
|
||||
} else if (error === 'redirect') {
|
||||
// In a real implementation, you'd use redirect('/')
|
||||
notFound();
|
||||
case 'error':
|
||||
// For now, treat errors as notFound
|
||||
// In a full implementation, you might render an error page
|
||||
} else {
|
||||
// For other errors, show notFound for now
|
||||
notFound();
|
||||
case 'ok':
|
||||
return <ProfileLeaguesPageClient pageDto={result.dto} />;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const viewData = result.unwrap();
|
||||
return <ProfileLeaguesTemplate viewData={viewData} />;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
'use client';
|
||||
|
||||
import type { Result } from '@/lib/contracts/Result';
|
||||
import type { SponsorshipRequestsViewData } from '@/lib/view-data/SponsorshipRequestsViewData';
|
||||
import { SponsorshipRequestsTemplate } from '@/templates/SponsorshipRequestsTemplate';
|
||||
|
||||
interface SponsorshipRequestsClientProps {
|
||||
viewData: SponsorshipRequestsViewData;
|
||||
onAccept: (requestId: string) => Promise<Result<void, string>>;
|
||||
onReject: (requestId: string, reason?: string) => Promise<Result<void, string>>;
|
||||
}
|
||||
|
||||
export function SponsorshipRequestsClient({ viewData, onAccept, onReject }: SponsorshipRequestsClientProps) {
|
||||
const handleAccept = async (requestId: string) => {
|
||||
const result = await onAccept(requestId);
|
||||
if (result.isErr()) {
|
||||
console.error('Failed to accept request:', result.getError());
|
||||
}
|
||||
};
|
||||
|
||||
const handleReject = async (requestId: string, reason?: string) => {
|
||||
const result = await onReject(requestId, reason);
|
||||
if (result.isErr()) {
|
||||
console.error('Failed to reject request:', result.getError());
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<SponsorshipRequestsTemplate
|
||||
viewData={viewData}
|
||||
onAccept={handleAccept}
|
||||
onReject={handleReject}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -13,7 +13,7 @@ interface SponsorshipRequestsPageClientProps {
|
||||
export function SponsorshipRequestsPageClient({ viewData, onAccept, onReject }: SponsorshipRequestsPageClientProps) {
|
||||
return (
|
||||
<SponsorshipRequestsTemplate
|
||||
data={viewData.sections}
|
||||
viewData={viewData}
|
||||
onAccept={async (requestId) => {
|
||||
await onAccept(requestId);
|
||||
}}
|
||||
|
||||
@@ -1,26 +1,57 @@
|
||||
'use server';
|
||||
|
||||
import { AcceptSponsorshipRequestMutation } from '@/lib/mutations/sponsors/AcceptSponsorshipRequestMutation';
|
||||
import { RejectSponsorshipRequestMutation } from '@/lib/mutations/sponsors/RejectSponsorshipRequestMutation';
|
||||
import type { AcceptSponsorshipRequestCommand } from '@/lib/services/sponsors/SponsorshipRequestsService';
|
||||
import type { RejectSponsorshipRequestCommand } from '@/lib/services/sponsors/SponsorshipRequestsService';
|
||||
import { SessionGateway } from '@/lib/gateways/SessionGateway';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { routes } from '@/lib/routing/RouteConfig';
|
||||
|
||||
export async function acceptSponsorshipRequest(
|
||||
command: AcceptSponsorshipRequestCommand,
|
||||
): Promise<void> {
|
||||
requestId: string,
|
||||
): Promise<Result<void, string>> {
|
||||
// Get session for actorDriverId
|
||||
const sessionGateway = new SessionGateway();
|
||||
const session = await sessionGateway.getSession();
|
||||
const actorDriverId = session?.user?.primaryDriverId;
|
||||
|
||||
if (!actorDriverId) {
|
||||
return Result.err('Not authenticated');
|
||||
}
|
||||
|
||||
const mutation = new AcceptSponsorshipRequestMutation();
|
||||
const result = await mutation.execute(command);
|
||||
const result = await mutation.execute({ requestId, actorDriverId });
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new Error('Failed to accept sponsorship request');
|
||||
console.error('Failed to accept sponsorship request:', result.getError());
|
||||
return Result.err(result.getError());
|
||||
}
|
||||
|
||||
revalidatePath(routes.protected.profileSponsorshipRequests);
|
||||
return Result.ok(undefined);
|
||||
}
|
||||
|
||||
export async function rejectSponsorshipRequest(
|
||||
command: RejectSponsorshipRequestCommand,
|
||||
): Promise<void> {
|
||||
requestId: string,
|
||||
reason?: string,
|
||||
): Promise<Result<void, string>> {
|
||||
// Get session for actorDriverId
|
||||
const sessionGateway = new SessionGateway();
|
||||
const session = await sessionGateway.getSession();
|
||||
const actorDriverId = session?.user?.primaryDriverId;
|
||||
|
||||
if (!actorDriverId) {
|
||||
return Result.err('Not authenticated');
|
||||
}
|
||||
|
||||
const mutation = new RejectSponsorshipRequestMutation();
|
||||
const result = await mutation.execute(command);
|
||||
const result = await mutation.execute({ requestId, actorDriverId, reason: reason || null });
|
||||
|
||||
if (result.isErr()) {
|
||||
throw new Error('Failed to reject sponsorship request');
|
||||
console.error('Failed to reject sponsorship request:', result.getError());
|
||||
return Result.err(result.getError());
|
||||
}
|
||||
|
||||
revalidatePath(routes.protected.profileSponsorshipRequests);
|
||||
return Result.ok(undefined);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,33 @@
|
||||
import { SponsorshipRequestsTemplate } from '@/templates/SponsorshipRequestsTemplate';
|
||||
import { notFound } from 'next/navigation';
|
||||
import { SponsorshipRequestsPageQuery } from '@/lib/page-queries/page-queries/SponsorshipRequestsPageQuery';
|
||||
import { SponsorshipRequestsClient } from './SponsorshipRequestsClient';
|
||||
import { acceptSponsorshipRequest, rejectSponsorshipRequest } from './actions';
|
||||
|
||||
export default async function SponsorshipRequestsPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Record<string, string>;
|
||||
}) {
|
||||
return <SponsorshipRequestsTemplate searchParams={searchParams} />;
|
||||
export default async function SponsorshipRequestsPage() {
|
||||
// Execute PageQuery
|
||||
const queryResult = await SponsorshipRequestsPageQuery.execute();
|
||||
|
||||
if (queryResult.isErr()) {
|
||||
const error = queryResult.getError();
|
||||
|
||||
if (error === 'notFound') {
|
||||
notFound();
|
||||
} else if (error === 'redirect') {
|
||||
// In a real implementation, you'd use redirect('/')
|
||||
notFound();
|
||||
} else {
|
||||
// For other errors, show notFound for now
|
||||
notFound();
|
||||
}
|
||||
}
|
||||
|
||||
const viewData = queryResult.unwrap();
|
||||
|
||||
return (
|
||||
<SponsorshipRequestsClient
|
||||
viewData={viewData}
|
||||
onAccept={acceptSponsorshipRequest}
|
||||
onReject={rejectSponsorshipRequest}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user