Skip to content

Commit

Permalink
feat(client):Create with Jovu button
Browse files Browse the repository at this point in the history
  • Loading branch information
yuval-hazaz committed May 9, 2024
1 parent 695d017 commit 9ea5aaa
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { EnumButtonStyle } from "@amplication/ui/design-system";
import "./JovuLogo.scss";
import { useAssistantContext } from "./context/AssistantContext";
import { useCallback } from "react";
import { Button } from "../Components/Button";
import { AnalyticsEventNames } from "../util/analytics-events.types";
import { useCallback } from "react";
import "./JovuLogo.scss";
import { useAssistantContext } from "./context/AssistantContext";

const CLASS_NAME = "ask-jovu-button";

type Props = {
message: string;
onClick: () => void;
onCreateWithJovuClicked: () => void;
disabled?: boolean;
eventOriginLocation: string;
};

const CreateWithJovuButton = ({
message,
onClick,
onCreateWithJovuClicked,
disabled,
eventOriginLocation,
}: Props) => {
Expand All @@ -25,11 +25,12 @@ const CreateWithJovuButton = ({
const handleClick = useCallback(() => {
sendMessage(message);
setOpen(true);
onClick && onClick();
}, [message, onClick, sendMessage, setOpen]);
onCreateWithJovuClicked && onCreateWithJovuClicked();
}, [message, onCreateWithJovuClicked, sendMessage, setOpen]);

return (
<Button
type="button"
disabled={processingMessage || disabled}
className={CLASS_NAME}
buttonStyle={EnumButtonStyle.GradientFull}
Expand Down
8 changes: 4 additions & 4 deletions packages/amplication-client/src/Entity/NewEntity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ const NewEntity = ({ resourceId, onSuccess }: Props) => {
autoComplete="off"
/>
<FlexItem
direction={EnumFlexDirection.Row}
margin={EnumFlexItemMargin.Top}
direction={EnumFlexDirection.Column}
margin={EnumFlexItemMargin.None}
>
<Button
type="submit"
Expand All @@ -309,8 +309,8 @@ const NewEntity = ({ resourceId, onSuccess }: Props) => {
Create Entity
</Button>
<CreateWithJovuButton
message={`Create a new entity ${formik.values.displayName}. Include common fields, and relations to other entities when needed.`}
onClick={handleDismissConfirmationInstall}
message={`Create a new entity ${formik.values.displayName}. Create common fields that should be part of this data model, and create relations to other entities when needed.`}
onCreateWithJovuClicked={onSuccess}
disabled={!formik.isValid || loading}
eventOriginLocation="New Entity Dialog"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ type Props = {
buttonStyle?: EnumButtonStyle;
};

const FORM_SCHEMA = {
required: ["displayName"],
properties: {
displayName: {
type: "string",
minLength: 2,
},
},
};

const INITIAL_VALUES: Partial<models.ModuleAction> = {
name: "",
displayName: "",
description: "",
};

const NewModuleAction = ({
resourceId,
moduleId,
Expand Down Expand Up @@ -99,11 +83,9 @@ const NewModuleAction = ({
return (
<div>
{dialogOpen && (
<NewModuleChild<models.ModuleAction>
<NewModuleChild
resourceId={resourceId}
moduleId={moduleId}
validationSchema={FORM_SCHEMA}
initialValues={INITIAL_VALUES}
loading={loading}
errorMessage={errorMessage}
typeName={"Action"}
Expand Down
21 changes: 2 additions & 19 deletions packages/amplication-client/src/ModuleDto/NewModuleDto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ type Props = {
navigateToDtoOnCreate?: boolean;
};

const FORM_SCHEMA = {
required: ["displayName"],
properties: {
displayName: {
type: "string",
minLength: 2,
},
},
};

const INITIAL_VALUES: Partial<models.ModuleDto> = {
name: "",
displayName: "",
description: "",
};

const NewModuleDto = ({
resourceId,
moduleId,
Expand Down Expand Up @@ -88,17 +72,16 @@ const NewModuleDto = ({
history,
currentWorkspace?.id,
currentProject?.id,
navigateToDtoOnCreate,
]
);

const errorMessage = formatError(error);

return (
<NewModuleChild<models.ModuleDto>
<NewModuleChild
resourceId={resourceId}
moduleId={moduleId}
validationSchema={FORM_SCHEMA}
initialValues={INITIAL_VALUES}
loading={loading}
errorMessage={errorMessage}
typeName={"DTO"}
Expand Down
21 changes: 2 additions & 19 deletions packages/amplication-client/src/ModuleDto/NewModuleDtoEnum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ type Props = {
navigateToDtoOnCreate?: boolean;
};

const FORM_SCHEMA = {
required: ["displayName"],
properties: {
displayName: {
type: "string",
minLength: 2,
},
},
};

const INITIAL_VALUES: Partial<models.ModuleDto> = {
name: "",
displayName: "",
description: "",
};

const NewModuleDtoEnum = ({
resourceId,
moduleId,
Expand Down Expand Up @@ -87,18 +71,17 @@ const NewModuleDtoEnum = ({
history,
currentWorkspace?.id,
currentProject?.id,
navigateToDtoOnCreate,
]
);

const errorMessage = formatError(error);

return (
<div>
<NewModuleChild<models.ModuleDto>
<NewModuleChild
resourceId={resourceId}
moduleId={moduleId}
validationSchema={FORM_SCHEMA}
initialValues={INITIAL_VALUES}
loading={loading}
errorMessage={errorMessage}
typeName={"Enum"}
Expand Down

0 comments on commit 9ea5aaa

Please sign in to comment.