Skip to content

Commit 57dfc2c

Browse files
authored
Add currency select (saleor#1047)
1 parent 5dc219e commit 57dfc2c

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/ui/components/ChannelSelect.tsx

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use client";
2+
3+
import { useParams, useRouter } from "next/navigation";
4+
5+
export const ChannelSelect = ({
6+
channels,
7+
}: {
8+
channels: { id: string; name: string; slug: string; currencyCode: string }[];
9+
}) => {
10+
const router = useRouter();
11+
const params = useParams<{ channel: string }>();
12+
13+
return (
14+
<select
15+
className="h-10 w-fit rounded-md border border-neutral-300 bg-transparent bg-white px-4 py-2 pr-10 text-sm placeholder:text-neutral-500 focus:border-black focus:ring-black"
16+
onChange={(e) => {
17+
const newChannel = e.currentTarget.value;
18+
return router.push(`/${newChannel}`);
19+
}}
20+
>
21+
{channels.map((channel) => (
22+
<option key={channel.id} value={channel.slug} selected={params.channel === channel.slug}>
23+
{channel.currencyCode}
24+
</option>
25+
))}
26+
</select>
27+
);
28+
};

src/ui/components/Footer.tsx

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import { LinkWithChannel } from "../atoms/LinkWithChannel";
2-
import { MenuGetBySlugDocument } from "@/gql/graphql";
2+
import { ChannelSelect } from "./ChannelSelect";
3+
import { ChannelsListDocument, MenuGetBySlugDocument } from "@/gql/graphql";
34
import { executeGraphQL } from "@/lib/graphql";
45

56
export async function Footer({ channel }: { channel: string }) {
67
const footerLinks = await executeGraphQL(MenuGetBySlugDocument, {
78
variables: { slug: "footer", channel },
89
revalidate: 60 * 60 * 24,
910
});
11+
const channels = process.env.SALEOR_APP_TOKEN
12+
? await executeGraphQL(ChannelsListDocument, {
13+
withAuth: false, // disable cookie-based auth for this call
14+
headers: {
15+
// and use app token instead
16+
Authorization: `Bearer ${process.env.SALEOR_APP_TOKEN}`,
17+
},
18+
})
19+
: null;
1020
const currentYear = new Date().getFullYear();
1121

1222
return (
@@ -61,6 +71,14 @@ export async function Footer({ channel }: { channel: string }) {
6171
})}
6272
</div>
6373

74+
{channels?.channels && (
75+
<div className="mb-4 text-neutral-500">
76+
<label>
77+
<span className="text-sm">Change currency:</span> <ChannelSelect channels={channels.channels} />
78+
</label>
79+
</div>
80+
)}
81+
6482
<div className="flex flex-col justify-between border-t border-neutral-200 py-10 sm:flex-row">
6583
<p className="text-sm text-neutral-500">Copyright &copy; {currentYear} Your Store, Inc.</p>
6684
<p className="text-sm text-neutral-500">Powered by Saleor</p>

0 commit comments

Comments
 (0)