Skip to content

Commit

Permalink
Merge pull request #122 from midday-ai/feature/connect-bank-country-code
Browse files Browse the repository at this point in the history
Save country code
  • Loading branch information
pontusab committed May 17, 2024
2 parents 6487e94 + f48d07e commit 9d411df
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 11 deletions.
15 changes: 15 additions & 0 deletions apps/dashboard/src/actions/change-country-code-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use server";

import { Cookies } from "@/utils/constants";
import { cookies } from "next/headers";
import { z } from "zod";
import { action } from "./safe-action";

export const changeCountryCodeAction = action(z.string(), async (value) => {
cookies().set({
name: Cookies.CountryCode,
value,
});

return value;
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export default async function Layout({
children: React.ReactNode;
}) {
const user = await getUser();
const countryCode = getCountryCode();
const countryCode = cookies().has(Cookies.CountryCode)
? cookies().get(Cookies.CountryCode)?.value
: getCountryCode();

const isEU = isEUCountry(countryCode);
const mobileOverlay = cookies().has(Cookies.MobileOverlay);

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/components/country-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function CountrySelector({ defaultValue, onSelect }) {
</PopoverTrigger>
<PopoverContentWithoutPortal className="w-[225px] p-0">
<Command>
<CommandInput placeholder="Search country..." className="h-9" />
<CommandInput placeholder="Search country..." className="h-9 px-2" />
<CommandEmpty>No country found.</CommandEmpty>
<CommandGroup className="overflow-y-auto max-h-[230px] pt-2">
{Object.values(countries).map((country) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { createEndUserAgreementAction } from "@/actions/banks/create-end-user-agreement-action";
import { getBanks } from "@/actions/banks/get-banks";
import { changeCountryCodeAction } from "@/actions/change-country-code-action";
import { Button } from "@midday/ui/button";
import {
Dialog,
Expand Down Expand Up @@ -102,6 +103,10 @@ export function ConnectGoCardLessModal({ countryCode: initialCountryCode }) {
const [results, setResults] = useState([]);
const [filteredResults, setFilteredResults] = useState([]);

const changeCountryCode = useAction(changeCountryCodeAction, {
onSuccess: (value) => setCountryCode(value),
});

const createEndUserAgreement = useAction(createEndUserAgreementAction);

const [step, setStep] = useQueryState("step");
Expand Down Expand Up @@ -177,7 +182,7 @@ export function ConnectGoCardLessModal({ countryCode: initialCountryCode }) {

<CountrySelector
defaultValue={countryCode}
onSelect={setCountryCode}
onSelect={changeCountryCode.execute}
/>
</div>

Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/src/components/modals/select-bank-accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ export function SelectBankAccountsModal({ countryCode }: Props) {
accessToken: token,
enrollmentId: enrollment_id,
accounts: data.map((account) => ({
account_id: account.id,
bank_name: account.institution.name,
currency: account.currency,
name: account.name,
institution_id: account.institution.id,
logo_url: account.institution?.logo,
account_id: account.id,
bank_name: account.institution.name,
currency: account.currency,
enabled: false,
})),
});
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export const Cookies = {
TrackingConsent: "tracking-consent",
ChartCurrency: "chart-currency",
InboxOrder: "inbox-order",
CountryCode: "country-code",
};
6 changes: 2 additions & 4 deletions packages/ui/src/components/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const DialogContent = React.forwardRef<
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[90vw] max-w-xl border dark:border-none dark:p-px text-primary rounded-lg z-50 data-[state=closed]:animate-[dialog-content-hide_100ms] data-[state=open]:animate-[dialog-content-show_100ms]",
"fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[90vw] max-w-xl border dark:border-none dark:p-px text-primary z-50 data-[state=closed]:animate-[dialog-content-hide_100ms] data-[state=open]:animate-[dialog-content-show_100ms]",
className
)}
style={{
Expand All @@ -44,9 +44,7 @@ const DialogContent = React.forwardRef<
}}
{...props}
>
<div className="bg-background p-2 rounded-lg dark:rounded-[8px]">
{children}
</div>
<div className="bg-background p-2">{children}</div>

{!hideClose && (
<DialogPrimitive.Close className="absolute right-6 top-6 opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
<input
type={type}
className={cn(
"flex h-9 w-full rounded-md border bg-transparent px-3 py-1 text-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",
"flex h-9 w-full border bg-transparent px-3 py-1 text-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",
className
)}
ref={ref}
Expand Down

0 comments on commit 9d411df

Please sign in to comment.