Skip to content

Commit

Permalink
PG사를 변경해도 결제수단이 유지되도록 개선 (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
CirnoV authored Dec 3, 2024
1 parent 9a8d3fa commit ab1dd84
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/state/interactive-docs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
createEffect,
createMemo,
createSignal,
on,
type Setter,
untrack,
} from "solid-js";
import { createStore } from "solid-js/store";

Expand Down Expand Up @@ -112,6 +112,7 @@ const [InteractiveDocsProvider, useInteractiveDocs] = createContextProvider(
const [preview, setPreview] = createSignal<Component | undefined>(
undefined,
);
const pgName = createMemo(() => params.pg.name);
const pgOptions = createMemo(() => initial().pgOptions);
createEffect(() => {
const pg = Object.keys(pgOptions())[0] as Pg | undefined;
Expand Down Expand Up @@ -218,14 +219,19 @@ const [InteractiveDocsProvider, useInteractiveDocs] = createContextProvider(
void highlighterInstance.then(setHighlighter);

// PG사 변경 시 payMethods 초기화
createEffect(() => {
const pg = params.pg.name;
setParams(
"pg",
"payMethods",
untrack(() => pgOptions()[pg]!.payMethods[0]!),
);
});
createEffect(
on([pgName, pgOptions], ([pgName, pgOptions]) => {
const pgOption = pgOptions[pgName];
if (!pgOption) return;

const payMethod = pgOption.payMethods.find(
(method) => method === params.pg.payMethods,
);
if (payMethod === undefined && pgOption.payMethods[0]) {
setParams("pg", "payMethods", pgOption.payMethods[0]);
}
}),
);

return {
pgOptions,
Expand Down

0 comments on commit ab1dd84

Please sign in to comment.