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 authored and luzzif committed Nov 1, 2023
1 parent 747ef73 commit d5cf7e6
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

2 comments on commit d5cf7e6

@vercel
Copy link

@vercel vercel bot commented on d5cf7e6 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./packages/ui

ui-carrot-labs.vercel.app
ui-git-main-carrot-labs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on d5cf7e6 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

host-frontend – ./packages/frontend

host-frontend-carrot-labs.vercel.app
host-frontend-git-main-carrot-labs.vercel.app

Please sign in to comment.