forked from appsmithorg/appsmith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: requesting new integration ui to accept users preferences about…
… the new integrations (appsmithorg#38012)
- Loading branch information
1 parent
c4c33b5
commit 11281c8
Showing
7 changed files
with
260 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
src/pages/Editor/IntegrationEditor/RequestNewIntegration/form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { Button, Flex, toast } from "@appsmith/ads"; | ||
import { Close } from "@radix-ui/react-dialog"; | ||
import { createMessage, REQUEST_NEW_INTEGRATIONS } from "ee/constants/messages"; | ||
import type { AppState } from "ee/reducers"; | ||
import React from "react"; | ||
import { connect } from "react-redux"; | ||
import { | ||
Field, | ||
formValueSelector, | ||
getFormSyncErrors, | ||
reduxForm, | ||
type FormErrors, | ||
type InjectedFormProps, | ||
} from "redux-form"; | ||
import { getCurrentUser } from "selectors/usersSelectors"; | ||
import styled from "styled-components"; | ||
import { isEmail } from "utils/formhelpers"; | ||
import ReduxFormTextField from "components/utils/ReduxFormTextField"; | ||
import AnalyticsUtil from "ee/utils/AnalyticsUtil"; | ||
|
||
const FormWrapper = styled.form` | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--ads-spaces-7); | ||
`; | ||
|
||
const RequestIntegrationForm = (props: RequestIntegrationFormProps) => { | ||
const onSubmit = (values: RequestIntegrationFormValues) => { | ||
AnalyticsUtil.logEvent("REQUEST_INTEGRATION_SUBMITTED", { | ||
integration_name: values.integration, | ||
use_case_description: values.useCase || "", | ||
email: values.email, | ||
}); | ||
toast.show(createMessage(REQUEST_NEW_INTEGRATIONS.SUCCESS_TOAST_MESSAGE), { | ||
kind: "success", | ||
}); | ||
props.closeModal(); | ||
}; | ||
|
||
return ( | ||
<FormWrapper onSubmit={props.handleSubmit(onSubmit)}> | ||
<Field | ||
component={ReduxFormTextField} | ||
label={createMessage( | ||
REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_INTEGRATION.LABEL, | ||
)} | ||
name={REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_INTEGRATION.NAME} | ||
placeholder={createMessage( | ||
REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_INTEGRATION.PLACEHOLDER, | ||
)} | ||
size="md" | ||
/> | ||
<Field | ||
component={ReduxFormTextField} | ||
label={createMessage( | ||
REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_USECASE.LABEL, | ||
)} | ||
name={REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_USECASE.NAME} | ||
placeholder={createMessage( | ||
REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_USECASE.PLACEHOLDER, | ||
)} | ||
size="md" | ||
type="textarea" | ||
/> | ||
<Field | ||
component={ReduxFormTextField} | ||
description={createMessage( | ||
REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_EMAIL.DESCRIPTION, | ||
)} | ||
label={createMessage( | ||
REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_EMAIL.LABEL, | ||
)} | ||
name={REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_EMAIL.NAME} | ||
size="md" | ||
type="email" | ||
/> | ||
<Flex gap="spaces-7" justifyContent="flex-end" marginTop="spaces-3"> | ||
<Close> | ||
<Button aria-label="Close" kind="secondary" size="md"> | ||
{createMessage(REQUEST_NEW_INTEGRATIONS.CANCEL_BUTTON)} | ||
</Button> | ||
</Close> | ||
<Button isDisabled={props.invalid} size="md" type="submit"> | ||
{createMessage(REQUEST_NEW_INTEGRATIONS.REQUEST_BUTTON)} | ||
</Button> | ||
</Flex> | ||
</FormWrapper> | ||
); | ||
}; | ||
|
||
const REQUEST_NEW_INTEGRATION_FORM_NAME = "REQUEST_NEW_INTEGRATION"; | ||
|
||
const selector = formValueSelector(REQUEST_NEW_INTEGRATION_FORM_NAME); | ||
|
||
interface RequestIntegrationFormValues { | ||
integration?: string; | ||
email?: string; | ||
useCase?: string; | ||
} | ||
|
||
type RequestIntegrationFormProps = RequestIntegrationFormValues & { | ||
formSyncErrors?: FormErrors<string, string>; | ||
closeModal: () => void; | ||
} & InjectedFormProps< | ||
RequestIntegrationFormValues, | ||
{ | ||
formSyncErrors?: FormErrors<string, string>; | ||
closeModal: () => void; | ||
} | ||
>; | ||
|
||
const validate = (values: RequestIntegrationFormValues) => { | ||
const errors: Partial<RequestIntegrationFormValues> = {}; | ||
|
||
if (!values.integration) { | ||
errors.integration = createMessage( | ||
REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_INTEGRATION.ERROR, | ||
); | ||
} | ||
|
||
if (!values.email || !isEmail(values.email)) { | ||
errors.email = createMessage( | ||
REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_EMAIL.ERROR, | ||
); | ||
} | ||
|
||
return errors; | ||
}; | ||
|
||
export default connect((state: AppState) => { | ||
const currentUser = getCurrentUser(state); | ||
|
||
return { | ||
integration: selector(state, "integration"), | ||
email: selector(state, "email"), | ||
useCase: selector(state, "useCase"), | ||
initialValues: { | ||
email: currentUser?.email, | ||
}, | ||
formSyncErrors: getFormSyncErrors(REQUEST_NEW_INTEGRATION_FORM_NAME)(state), | ||
}; | ||
}, null)( | ||
reduxForm< | ||
RequestIntegrationFormValues, | ||
{ | ||
formSyncErrors?: FormErrors<string, string>; | ||
closeModal: () => void; | ||
} | ||
>({ | ||
validate, | ||
form: REQUEST_NEW_INTEGRATION_FORM_NAME, | ||
enableReinitialize: true, | ||
})(RequestIntegrationForm), | ||
); |
59 changes: 59 additions & 0 deletions
59
src/pages/Editor/IntegrationEditor/RequestNewIntegration/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
Button, | ||
Flex, | ||
Modal, | ||
ModalContent, | ||
ModalHeader, | ||
ModalTrigger, | ||
} from "@appsmith/ads"; | ||
import { createMessage, REQUEST_NEW_INTEGRATIONS } from "ee/constants/messages"; | ||
import React, { useState, type ReactNode } from "react"; | ||
import styled from "styled-components"; | ||
import Form from "./form"; | ||
import AnalyticsUtil from "ee/utils/AnalyticsUtil"; | ||
|
||
const RequestNewIntegrationWrapper = styled(Flex)` | ||
padding: var(--ads-spaces-7); | ||
border-top: 1px solid var(--ads-v2-colors-content-surface-default-border); | ||
position: sticky; | ||
bottom: 0; | ||
background: var(--ads-v2-color-bg); | ||
`; | ||
|
||
const ModalContentWrapper = styled(ModalContent)` | ||
max-width: 518px; | ||
`; | ||
|
||
function RequestModal({ children }: { children: ReactNode }) { | ||
const [open, setOpen] = useState(false); | ||
|
||
return ( | ||
<Modal onOpenChange={setOpen} open={open}> | ||
<ModalTrigger>{children}</ModalTrigger> | ||
<ModalContentWrapper> | ||
<ModalHeader> | ||
{createMessage(REQUEST_NEW_INTEGRATIONS.REQUEST_MODAL_HEADING)} | ||
</ModalHeader> | ||
<Form closeModal={() => setOpen(false)} /> | ||
</ModalContentWrapper> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default function RequestNewIntegration() { | ||
return ( | ||
<RequestNewIntegrationWrapper gap="spaces-5"> | ||
<p>{createMessage(REQUEST_NEW_INTEGRATIONS.UNABLE_TO_FIND)}</p> | ||
<RequestModal> | ||
<Button | ||
kind="secondary" | ||
onClick={() => { | ||
AnalyticsUtil.logEvent("REQUEST_INTEGRATION_CTA"); | ||
}} | ||
> | ||
{createMessage(REQUEST_NEW_INTEGRATIONS.REQUEST_NEW_BUTTON)} | ||
</Button> | ||
</RequestModal> | ||
</RequestNewIntegrationWrapper> | ||
); | ||
} |