-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
193 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./use-get-banner"; |
20 changes: 20 additions & 0 deletions
20
core/application/react-query-adapter/banner/client/use-get-banner.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
|
||
import { | ||
UseQueryFacadeParams, | ||
useQueryAdapter, | ||
} from "@/core/application/react-query-adapter/helpers/use-query-adapter"; | ||
import { bootstrap } from "@/core/bootstrap"; | ||
import { BannerFacadePort } from "@/core/domain/banner/input/banner-facade-port"; | ||
import { BannerInterface } from "@/core/domain/banner/models/banner-model"; | ||
|
||
export function useGetBanner({ options }: UseQueryFacadeParams<BannerFacadePort["getBanner"], BannerInterface>) { | ||
const bannerStoragePort = bootstrap.getBannerStoragePortForClient(); | ||
|
||
return useQuery( | ||
useQueryAdapter({ | ||
...bannerStoragePort.getBanner({}), | ||
options, | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as client from "./client"; | ||
|
||
export const BannerReactQueryAdapter = { | ||
client, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { BootstrapConstructor } from "@/core/bootstrap/index"; | ||
import { BannerClientAdapterMock } from "@/core/infrastructure/marketplace-api-client-adapter/mock-adapters/banner-client-adapter-mock"; | ||
import { UserClientAdapterMock } from "@/core/infrastructure/marketplace-api-client-adapter/mock-adapters/user-client-adapter-mock"; | ||
|
||
export const bootstrapConstructorMock: BootstrapConstructor = { | ||
userStoragePortForClient: new UserClientAdapterMock(), | ||
userStoragePortForServer: new UserClientAdapterMock(), | ||
bannerStoragePortForClient: new BannerClientAdapterMock(), | ||
bannerStoragePortForServer: new BannerClientAdapterMock(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { BannerInterface } from "@/core/domain/banner/models/banner-model"; | ||
import { components } from "@/core/infrastructure/marketplace-api-client-adapter/__generated/api"; | ||
import { | ||
HttpClientParameters, | ||
HttpStorageResponse, | ||
} from "@/core/infrastructure/marketplace-api-client-adapter/http/http-client/http-client.types"; | ||
|
||
/* --------------------------------- Get Banner -------------------------------- */ | ||
|
||
export type GetBannerResponse = components["schemas"]["BannerResponse"]; | ||
|
||
export type GetBannerPortParams = HttpClientParameters<object>; | ||
|
||
export type GetBannerPortResponse = HttpStorageResponse<BannerInterface>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { GetBannerPortParams, GetBannerPortResponse } from "@/core/domain/banner/banner-contract.types"; | ||
|
||
export interface BannerFacadePort { | ||
getBanner(p: GetBannerPortParams): GetBannerPortResponse; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { components } from "@/core/infrastructure/marketplace-api-client-adapter/__generated/api"; | ||
|
||
export type BannerResponse = components["schemas"]["BannerResponse"]; | ||
|
||
export interface BannerInterface extends BannerResponse {} | ||
|
||
export class Banner implements BannerInterface { | ||
buttonIconSlug!: BannerResponse["buttonIconSlug"]; | ||
buttonLinkUrl!: BannerResponse["buttonLinkUrl"]; | ||
buttonText!: BannerResponse["buttonText"]; | ||
id!: BannerResponse["id"]; | ||
text!: BannerResponse["text"]; | ||
|
||
constructor(props: BannerResponse) { | ||
Object.assign(this, props); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { GetBannerPortParams, GetBannerPortResponse } from "@/core/domain/banner/banner-contract.types"; | ||
|
||
export interface BannerStoragePort { | ||
routes: Record<string, string>; | ||
getBanner(p: GetBannerPortParams): GetBannerPortResponse; | ||
} |
32 changes: 32 additions & 0 deletions
32
core/infrastructure/marketplace-api-client-adapter/adapters/banner-client-adapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { GetBannerResponse } from "@/core/domain/banner/banner-contract.types"; | ||
import { Banner } from "@/core/domain/banner/models/banner-model"; | ||
import { BannerStoragePort } from "@/core/domain/banner/outputs/banner-storage-port"; | ||
import { HttpClient } from "@/core/infrastructure/marketplace-api-client-adapter/http/http-client/http-client"; | ||
|
||
export class BannerClientAdapter implements BannerStoragePort { | ||
constructor(private readonly client: HttpClient) {} | ||
|
||
routes = { | ||
getBanner: "banner", | ||
} as const; | ||
|
||
getBanner = () => { | ||
const path = this.routes["getBanner"]; | ||
const method = "GET"; | ||
const tag = HttpClient.buildTag({ path }); | ||
const request = async () => { | ||
const data = await this.client.request<GetBannerResponse>({ | ||
path, | ||
method, | ||
tag, | ||
}); | ||
|
||
return new Banner(data); | ||
}; | ||
|
||
return { | ||
request, | ||
tag, | ||
}; | ||
}; | ||
} |
10 changes: 10 additions & 0 deletions
10
...infrastructure/marketplace-api-client-adapter/mock-adapters/banner-client-adapter-mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BannerStoragePort } from "core/domain/banner/outputs/banner-storage-port"; | ||
import { mockHttpStorageResponse } from "@/core/infrastructure/marketplace-api-client-adapter/http/mock-http-client/mock-http-storage-response"; | ||
|
||
export class BannerClientAdapterMock implements BannerStoragePort { | ||
constructor() {} | ||
|
||
routes = {}; | ||
|
||
getBanner = mockHttpStorageResponse<BannerStoragePort["getBanner"]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
shared/features/navigation/primary-banner/primary-banner.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { ComponentProps } from "react"; | ||
|
||
import { BannerReactQueryAdapter } from "@/core/application/react-query-adapter/banner"; | ||
|
||
import { Skeleton } from "@/design-system/atoms/skeleton"; | ||
import { PlgBanner } from "@/design-system/organisms/plg-banner/plg-banner"; | ||
|
||
import { PrimaryBannerProps } from "@/shared/features/navigation/primary-banner/primary-banner.types"; | ||
|
||
export function PrimaryBanner({ isFolded }: PrimaryBannerProps) { | ||
const { data: bannerData, isLoading, isError } = BannerReactQueryAdapter.client.useGetBanner({}); | ||
|
||
function getCta(): ComponentProps<typeof PlgBanner>["cta"] { | ||
if (!bannerData?.buttonText || !bannerData?.buttonLinkUrl) return undefined; | ||
|
||
return { | ||
text: bannerData.buttonText, | ||
href: bannerData.buttonLinkUrl, | ||
// TODO @Mehdi @Backend add Banner avatar URL to bannerData response and show avatar in CTA | ||
}; | ||
} | ||
|
||
if (isLoading) { | ||
return <Skeleton className={"h-full w-full"} />; | ||
} | ||
|
||
if (isFolded || !bannerData || !bannerData.text || isError) { | ||
return <div className="flex-1" />; | ||
} | ||
|
||
return ( | ||
<div className="flex flex-1 overflow-hidden"> | ||
<div className="h-full w-[260px] min-w-[260px]"> | ||
<PlgBanner | ||
title={"title"} | ||
subTitle={"subtitle"} | ||
date={"10.06.2024"} | ||
description={bannerData.text} | ||
cta={getCta()} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
shared/features/navigation/primary-banner/primary-banner.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface PrimaryBannerProps { | ||
isFolded?: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters