Skip to content

Commit

Permalink
chore(frontend): update code to integrate new react library changes
Browse files Browse the repository at this point in the history
  • Loading branch information
luzzifoss committed Nov 1, 2023
1 parent 47ca22e commit 2cea0b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-hats-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@carrot-kpi/host-frontend": patch
---

Update frontend after React library changes
25 changes: 18 additions & 7 deletions packages/frontend/src/pages/create-with-template-id/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useInvalidateLatestKPITokens } from "../../hooks/useInvalidateLatestKPI
import { Layout } from "../../components/layout";
import { Permissioned } from "../../components/permissioned";
import { useIsCreatorAllowed } from "../../hooks/useIsCreatorAllowed";
import type { TemplateComponentStateUpdater } from "@carrot-kpi/react";

export function CreateWithTemplateId<S extends SerializableObject<S>>() {
const { i18n, t } = useTranslation();
Expand Down Expand Up @@ -133,12 +134,22 @@ export function CreateWithTemplateId<S extends SerializableObject<S>>() {
templateId,
]);

const handleChange = useCallback((state: S) => {
setDraftState((prevState) => ({
templateId: prevState.templateId,
state,
}));
}, []);
const handleStateChange = useCallback(
(stateOrUpdater: S | TemplateComponentStateUpdater<S>) => {
setDraftState((prevState) => {
const newState =
typeof stateOrUpdater === "function"
? stateOrUpdater(prevState.state)
: (stateOrUpdater as S);

return {
templateId: prevState.templateId,
state: newState,
};
});
},
[],
);

const handleCreate = useCallback(() => {
invalidateLatestKPITokens();
Expand Down Expand Up @@ -189,7 +200,7 @@ export function CreateWithTemplateId<S extends SerializableObject<S>>() {
i18n={i18n}
className={{ root: "w-full h-full" }}
state={draftState.state}
onChange={handleChange}
onStateChange={handleStateChange}
onCreate={handleCreate}
navigate={navigate}
onTx={addTransaction}
Expand Down

0 comments on commit 2cea0b1

Please sign in to comment.