PromucFlow_constructor/app/client/src/pages/setup/GetStarted.tsx
albinAppsmith 110e6085b8
feat: Renamed design system package (#19854)
## Description

This PR includes changes for renaming design system package. Since we
are building new package for the refactored design system components,
the old package is renaming to design-system-old.

Fixes #19536 

## Type of change

- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)


## How Has This Been Tested?

- Manual
- Jest
- Cypress

### Test Plan
> Add Testsmith test cases links that relate to this PR

### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)


## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
2023-01-23 09:20:47 +05:30

153 lines
3.9 KiB
TypeScript

import React from "react";
import { Button, FormGroup as StyledFormGroup } from "design-system-old";
import FormTextField from "components/utils/ReduxFormTextField";
import {
WELCOME_FORM_ROLE_FIELD_NAME,
WELCOME_FORM_ROLE_NAME_FIELD_NAME,
WELCOME_FORM_USECASE_FIELD_NAME,
WELCOME_NON_SUPER_FORM_NAME,
} from "@appsmith/constants/forms";
import {
createMessage,
WELCOME_ACTION,
WELCOME_FORM_NON_SUPER_USER_ROLE_DROPDOWN,
WELCOME_FORM_NON_SUPER_USER_USE_CASE,
WELCOME_FORM_ROLE,
} from "@appsmith/constants/messages";
import { connect } from "react-redux";
import { AppState } from "@appsmith/reducers";
import {
Field,
formValueSelector,
InjectedFormProps,
reduxForm,
} from "redux-form";
import styled from "styled-components";
import { DropdownWrapper, withDropdown } from "./common";
import { roleOptions, useCaseOptions } from "./constants";
const ActionContainer = styled.div`
margin-top: ${(props) => props.theme.spaces[15]}px;
`;
const StyledButton = styled(Button)`
width: 136px;
height: 38px;
font-size: 13px;
margin-top: ${(props) => props.theme.spaces[3]}px;
`;
type UserFormProps = {
onGetStarted?: (role?: string, useCase?: string) => void;
};
type NonSuperUserFormData = {
role?: string;
useCase?: string;
role_name?: string;
};
export function SuperUserForm(props: UserFormProps) {
return (
<ActionContainer>
<StyledButton
className="t--welcome-form-get-started"
onClick={() => props.onGetStarted && props.onGetStarted()}
text={createMessage(WELCOME_ACTION)}
/>
</ActionContainer>
);
}
const StyledNonSuperUserForm = styled.form`
width: 400px;
`;
const Space = styled.div`
height: 20px;
`;
const validate = (values: any) => {
const errors: any = {};
if (!values.role) {
errors.role = "Please select a role";
}
if (values.role === "other" && !values.role_name) {
errors.role_name = "Please enter a role";
}
if (!values.useCase) {
errors.useCase = "Please select an useCase";
}
return errors;
};
const DROPDOWN_WIDTH = "400px";
function NonSuperUser(
props: InjectedFormProps & UserFormProps & NonSuperUserFormData,
) {
return (
<StyledNonSuperUserForm>
<Space />
<DropdownWrapper
label={createMessage(WELCOME_FORM_NON_SUPER_USER_ROLE_DROPDOWN)}
>
<Field
asyncControl
component={withDropdown(roleOptions, DROPDOWN_WIDTH)}
name="role"
placeholder=""
type="text"
/>
</DropdownWrapper>
{props.role == "other" && (
<StyledFormGroup label={createMessage(WELCOME_FORM_ROLE)}>
<FormTextField name="role_name" placeholder="" type="text" />
</StyledFormGroup>
)}
<DropdownWrapper
label={createMessage(WELCOME_FORM_NON_SUPER_USER_USE_CASE)}
>
<Field
asyncControl
component={withDropdown(useCaseOptions, DROPDOWN_WIDTH)}
name="useCase"
placeholder=""
type="text"
/>
</DropdownWrapper>
<ActionContainer>
<StyledButton
className="t--get-started-button"
disabled={props.invalid}
onClick={() =>
props.onGetStarted &&
props.onGetStarted(
props.role !== "other" ? props.role : props.role_name,
props.useCase,
)
}
text={createMessage(WELCOME_ACTION)}
/>
</ActionContainer>
</StyledNonSuperUserForm>
);
}
const selector = formValueSelector(WELCOME_NON_SUPER_FORM_NAME);
export default connect((state: AppState) => {
return {
role: selector(state, WELCOME_FORM_ROLE_FIELD_NAME),
role_name: selector(state, WELCOME_FORM_ROLE_NAME_FIELD_NAME),
useCase: selector(state, WELCOME_FORM_USECASE_FIELD_NAME),
};
}, null)(
reduxForm<NonSuperUserFormData, UserFormProps>({
validate,
form: WELCOME_NON_SUPER_FORM_NAME,
touchOnBlur: true,
})(NonSuperUser),
);