Skip to content

Commit

Permalink
Update amplify
Browse files Browse the repository at this point in the history
  • Loading branch information
borajoo committed Oct 4, 2023
1 parent 2a0f9ec commit d052c70
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 202 deletions.
7 changes: 3 additions & 4 deletions src/ui-components/TimeslotCreateForm.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/** *************************************************************************
/***************************************************************************
* The contents of this file were generated with Amplify Studio. *
* Please refrain from making any modifications to this file. *
* Any changes to this file will be overwritten when running amplify pull. *
************************************************************************* */
**************************************************************************/

import * as React from "react";
import { EscapeHatchProps } from "@aws-amplify/ui-react/internal";
import { GridProps, TextFieldProps } from "@aws-amplify/ui-react";

import { EscapeHatchProps } from "@aws-amplify/ui-react/internal";
export declare type ValidationResponse = {
hasError: boolean;
errorMessage?: string;
Expand Down
103 changes: 38 additions & 65 deletions src/ui-components/TimeslotCreateForm.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
/** *************************************************************************
/***************************************************************************
* The contents of this file were generated with Amplify Studio. *
* Please refrain from making any modifications to this file. *
* Any changes to this file will be overwritten when running amplify pull. *
************************************************************************* */
**************************************************************************/

/* eslint-disable */
import * as React from "react";
import { fetchByPath, validateField } from "./utils";
import { Timeslot } from "../models";
import { getOverrideProps } from "@aws-amplify/ui-react/internal";
import {
Badge,
Button,
Expand All @@ -21,6 +18,9 @@ import {
TextField,
useTheme,
} from "@aws-amplify/ui-react";
import { getOverrideProps } from "@aws-amplify/ui-react/internal";
import { Timeslot } from "../models";
import { fetchByPath, validateField } from "./utils";
import { DataStore } from "aws-amplify";
function ArrayField({
items = [],
Expand All @@ -37,7 +37,14 @@ function ArrayField({
runValidationTasks,
errorMessage,
}) {
const { tokens } = useTheme();
const labelElement = <Text>{label}</Text>;
const {
tokens: {
components: {
fieldmessages: { error: errorStyles },
},
},
} = useTheme();
const [selectedBadgeIndex, setSelectedBadgeIndex] = React.useState();
const [isEditing, setIsEditing] = React.useState();
React.useEffect(() => {
Expand All @@ -53,9 +60,9 @@ function ArrayField({
const addItem = async () => {
const { hasError } = runValidationTasks();
if (
(currentFieldValue !== undefined ||
currentFieldValue !== null ||
currentFieldValue !== "") &&
currentFieldValue !== undefined &&
currentFieldValue !== null &&
currentFieldValue !== "" &&
!hasError
) {
const newItems = [...items];
Expand All @@ -69,45 +76,8 @@ function ArrayField({
setIsEditing(false);
}
};
return (
const arraySection = (
<React.Fragment>
{isEditing && children}
{!isEditing ? (
<>
<Text>{label}</Text>
<Button
onClick={() => {
setIsEditing(true);
}}
>
Add item
</Button>
</>
) : (
<Flex justifyContent="flex-end">
{(currentFieldValue || isEditing) && (
<Button
children="Cancel"
type="button"
size="small"
onClick={() => {
setFieldValue(defaultFieldValue);
setIsEditing(false);
setSelectedBadgeIndex(undefined);
}}
></Button>
)}
<Button
size="small"
variation="link"
color={tokens.colors.brand.primary[80]}
isDisabled={hasError}
onClick={addItem}
>
{selectedBadgeIndex !== undefined ? "Save" : "Add"}
</Button>
</Flex>
)}
{!!items?.length && (
<ScrollView height="inherit" width="inherit" maxHeight={"7rem"}>
{items.map((value, index) => {
Expand All @@ -128,7 +98,7 @@ function ArrayField({
setIsEditing(true);
}}
>
{value.toString()}
{getBadgeText ? getBadgeText(value) : value.toString()}
<Icon
style={{
cursor: "pointer",
Expand Down Expand Up @@ -213,15 +183,14 @@ export default function TimeslotCreateForm(props) {
onSuccess,
onError,
onSubmit,
onCancel,
onValidate,
onChange,
overrides,
...rest
} = props;
const initialValues = {
startTime: undefined,
endTime: undefined,
startTime: "",
endTime: "",
unavailableDates: [],
availableSundays: [],
riderUnavailableDates: [],
Expand Down Expand Up @@ -250,7 +219,7 @@ export default function TimeslotCreateForm(props) {
setErrors({});
};
const [currentUnavailableDatesValue, setCurrentUnavailableDatesValue] =
React.useState(undefined);
React.useState("");
const unavailableDatesRef = React.createRef();
const [currentAvailableSundaysValue, setCurrentAvailableSundaysValue] =
React.useState("");
Expand All @@ -267,7 +236,15 @@ export default function TimeslotCreateForm(props) {
availableSundays: [],
riderUnavailableDates: [],
};
const runValidationTasks = async (fieldName, value) => {
const runValidationTasks = async (
fieldName,
currentValue,
getDisplayValue
) => {
const value =
currentValue && getDisplayValue
? getDisplayValue(currentValue)
: currentValue;
let validationResponse = validateField(value, validations[fieldName]);
const customValidator = fetchByPath(onValidate, fieldName);
if (customValidator) {
Expand Down Expand Up @@ -332,8 +309,8 @@ export default function TimeslotCreateForm(props) {
}
}
}}
{...rest}
{...getOverrideProps(overrides, "TimeslotCreateForm")}
{...rest}
>
<TextField
label="Start time"
Expand Down Expand Up @@ -408,7 +385,7 @@ export default function TimeslotCreateForm(props) {
values = result?.unavailableDates ?? values;
}
setUnavailableDates(values);
setCurrentUnavailableDatesValue(undefined);
setCurrentUnavailableDatesValue("");
}}
currentFieldValue={currentUnavailableDatesValue}
label={"Unavailable dates"}
Expand All @@ -423,7 +400,7 @@ export default function TimeslotCreateForm(props) {
errorMessage={errors?.unavailableDates?.errorMessage}
setFieldValue={setCurrentUnavailableDatesValue}
inputFieldRef={unavailableDatesRef}
defaultFieldValue={undefined}
defaultFieldValue={""}
>
<TextField
label="Unavailable dates"
Expand All @@ -444,6 +421,7 @@ export default function TimeslotCreateForm(props) {
errorMessage={errors.unavailableDates?.errorMessage}
hasError={errors.unavailableDates?.hasError}
ref={unavailableDatesRef}
labelHidden={true}
{...getOverrideProps(overrides, "unavailableDates")}
></TextField>
</ArrayField>
Expand Down Expand Up @@ -567,21 +545,16 @@ export default function TimeslotCreateForm(props) {
<Button
children="Clear"
type="reset"
onClick={resetStateValues}
onClick={(event) => {
event.preventDefault();
resetStateValues();
}}
{...getOverrideProps(overrides, "ClearButton")}
></Button>
<Flex
gap="15px"
{...getOverrideProps(overrides, "RightAlignCTASubFlex")}
>
<Button
children="Cancel"
type="button"
onClick={() => {
onCancel && onCancel();
}}
{...getOverrideProps(overrides, "CancelButton")}
></Button>
<Button
children="Submit"
type="submit"
Expand Down
7 changes: 3 additions & 4 deletions src/ui-components/TimeslotUpdateForm.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/** *************************************************************************
/***************************************************************************
* The contents of this file were generated with Amplify Studio. *
* Please refrain from making any modifications to this file. *
* Any changes to this file will be overwritten when running amplify pull. *
************************************************************************* */
**************************************************************************/

import * as React from "react";
import { EscapeHatchProps } from "@aws-amplify/ui-react/internal";
import { GridProps, TextFieldProps } from "@aws-amplify/ui-react";
import { EscapeHatchProps } from "@aws-amplify/ui-react/internal";
import { Timeslot } from "../models";

export declare type ValidationResponse = {
hasError: boolean;
errorMessage?: string;
Expand Down
Loading

0 comments on commit d052c70

Please sign in to comment.