Skip to content

Commit

Permalink
feat(Booking): added hidden field
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Dobkowski committed Nov 12, 2024
1 parent e685cda commit 249877c
Show file tree
Hide file tree
Showing 8 changed files with 4,758 additions and 4,192 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"i18n-ally.localesPaths": [
"public/locales",
"src/features/i18n"
]
}
8,917 changes: 4,731 additions & 4,186 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/components/forms/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@ interface TextFieldProps {
name: string;
multiline?: boolean;
placeholder?: string;
hidden?: boolean;
}

const TextField: React.FC<TextFieldProps> = ({ label, name, multiline = false, placeholder }) => {
const TextField: React.FC<TextFieldProps> = ({ label, name, multiline = false, placeholder, hidden }) => {
const { t } = useTranslation(["forms"]);
const labelToDisplay = label === undefined ? t(`${name}Field`) : label;

const [field, meta] = useField({ name });

console.log("field", field);
const input = multiline ? (
<StyledTextArea id={name} placeholder={placeholder} rows={2} {...field} />
) : (
<StyledInput id={name} placeholder={placeholder} {...field} />
);

return (
<Column ai="stretch">
<Column ai="stretch" hidden={hidden}>
<StyledLabel htmlFor={name}>{labelToDisplay}</StyledLabel>
{input}
<Box h="13px" mt={0.5} mb={1}>
Expand Down
3 changes: 2 additions & 1 deletion src/components/layout/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import styled from "styled-components";
export interface ColumnProps extends BoxProps {
jc?: JustifyContent;
ai?: AlignItems;
hidden?: boolean;
}

export const Column = styled(Box)<ColumnProps>`
display: flex;
display: ${({ hidden }) => (hidden ? "none" : "flex")};
flex-direction: column;
justify-content: ${({ jc }) => jc ?? "space-between"};
align-items: ${({ ai }) => ai ?? "center"};
Expand Down
5 changes: 5 additions & 0 deletions src/features/service/api/queries/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ export const GET_SERVICE = gql`
order
required
}
... on FormFieldHidden {
fieldId
fieldType
label
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ const BookService = () => {
};

if (formFields === undefined || formFields.length === 0) return null;

return (
<Box mt={serviceType === BOOKING_FORM_TYPES.PREORDER ? 0 : 1.125}>
<WrapperCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ const FormComponent = ({ config }: FormComponentProps) => {
case "FILE_UPLOAD": {
return <FileUpload key={`booking-form-field-FILE_UPLOAD-${config.fieldId}`} {...config} label={label} />;
}
case "HIDDEN": {
return <TextField key={`booking-form-field-${config.fieldId}`} name={config.label} label={label} hidden />;
}
default: {
return null;
}
Expand Down
8 changes: 7 additions & 1 deletion src/models/formFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ export type FormFieldFileUpload = BaseFormField & {
multiple: boolean | null;
};

export type FormFieldHidden = BaseFormField & {
fieldType: "HIDDEN";
value: string;
};

export type FormField =
| FormFieldSystemFullName
| FormFieldSystemEmailAddress
Expand All @@ -134,4 +139,5 @@ export type FormField =
| FormFieldNumber
| FormFieldCheckbox
| FormFieldSelect
| FormFieldFileUpload;
| FormFieldFileUpload
| FormFieldHidden;

0 comments on commit 249877c

Please sign in to comment.