-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ksiuwr/bartacc/basic_forms_implementation
Add Register and Sign Up forms
- Loading branch information
Showing
27 changed files
with
830 additions
and
120 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import React, { PropsWithChildren } from "react"; | ||
|
||
export const CenteredContainer = ({ children }: PropsWithChildren) => { | ||
return <div className="mx-auto w-5/6 2xl:container lg:w-4/6">{children}</div>; | ||
return <div className="mx-auto w-11/12 2xl:container lg:w-4/6">{children}</div>; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Description } from "@headlessui/react"; | ||
import { FieldHandler } from "@reactivated"; | ||
import parse from "html-react-parser"; | ||
import React from "react"; | ||
|
||
interface BasicDescriptionProps { | ||
field: FieldHandler; | ||
} | ||
|
||
export const BasicDescription = ({ field }: BasicDescriptionProps) => { | ||
if (!field.help_text && !field.error) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<Description as="div" className="prose mx-2 max-w-none"> | ||
{field.error && ( | ||
<span className="block text-error">{parse(field.error)}</span> | ||
)} | ||
{field.help_text && ( | ||
<span className="block">{parse(field.help_text)}</span> | ||
)} | ||
</Description> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,51 @@ | ||
import { Field, Label } from "@headlessui/react"; | ||
import { Field } from "@headlessui/react"; | ||
import { FieldHandler } from "@reactivated"; | ||
import clsx from "clsx"; | ||
import React from "react"; | ||
import { WidgetHandler } from "reactivated/dist/forms"; | ||
import { DjangoFormsWidgetsCheckboxInput } from "reactivated/dist/generated"; | ||
import { BasicDescription } from "./BasicDescription"; | ||
import { BasicLabel } from "./BasicLabel"; | ||
import { BasicWidget } from "./BasicWidget"; | ||
|
||
interface BasicFormFieldProps { | ||
field: FieldHandler; | ||
disabled?: boolean; | ||
checked?: boolean; | ||
onCheckboxChange?: ( | ||
field: WidgetHandler<DjangoFormsWidgetsCheckboxInput>, | ||
value: boolean, | ||
) => void; | ||
} | ||
|
||
export const BasicFormField = ({ field }: BasicFormFieldProps) => { | ||
export const BasicFormField = ({ | ||
field, | ||
disabled = undefined, | ||
checked = undefined, | ||
onCheckboxChange = undefined, | ||
}: BasicFormFieldProps) => { | ||
const isCheckbox = field.tag === "django.forms.widgets.CheckboxInput"; | ||
|
||
return ( | ||
<Field className="mb-3"> | ||
<Label className="label font-semibold">{field.label}</Label> | ||
<BasicWidget field={field} /> | ||
<Field | ||
className="mb-4 flex flex-col" | ||
disabled={disabled === undefined ? field.disabled : disabled} | ||
> | ||
<div | ||
className={clsx( | ||
"flex", | ||
isCheckbox && "flex-row items-center gap-x-2", | ||
!isCheckbox && "flex-col", | ||
)} | ||
> | ||
<BasicLabel field={field} /> | ||
<BasicWidget | ||
field={field} | ||
checked={checked} | ||
onCheckboxChange={onCheckboxChange} | ||
/> | ||
</div> | ||
<BasicDescription field={field} /> | ||
</Field> | ||
); | ||
}; |
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,31 @@ | ||
import React, { PropsWithChildren } from "react"; | ||
|
||
import { CSRFToken, FormHandler } from "@reactivated"; | ||
import { FieldMap } from "reactivated/dist/forms"; | ||
import { Alert } from "../alert/Alert"; | ||
|
||
interface BasicFormWithCustomFieldsProps<T extends FieldMap> { | ||
form: FormHandler<T>; | ||
submitButtonLabel: string; | ||
} | ||
|
||
export const BasicFormWithCustomFields = <T extends FieldMap>({ | ||
form, | ||
submitButtonLabel, | ||
children, | ||
}: PropsWithChildren<BasicFormWithCustomFieldsProps<T>>) => { | ||
return ( | ||
<form method="POST"> | ||
<CSRFToken /> | ||
{form.nonFieldErrors?.map((error) => ( | ||
<Alert key={error} type="error"> | ||
{error} | ||
</Alert> | ||
))} | ||
{children} | ||
<button type="submit" className="btn btn-primary btn-lg my-4 w-full"> | ||
{submitButtonLabel} | ||
</button> | ||
</form> | ||
); | ||
}; |
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,16 @@ | ||
import { Label } from "@headlessui/react"; | ||
import { FieldHandler } from "@reactivated"; | ||
import React from "react"; | ||
|
||
interface BasicLabelProps { | ||
field: FieldHandler; | ||
} | ||
|
||
export const BasicLabel = ({ field }: BasicLabelProps) => { | ||
return ( | ||
<Label className="label inline-block text-wrap text-base font-semibold"> | ||
{field.label} | ||
{field.widget.required && <span className="mx-1 text-error">*</span>} | ||
</Label> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { useState } from "react"; | ||
import { WidgetHandler } from "reactivated/dist/forms"; | ||
import { DjangoFormsWidgetsCheckboxInput } from "reactivated/dist/generated"; | ||
import { BasicFormField } from "../forms/BasicFormField"; | ||
|
||
interface AccomodationFieldGroupProps { | ||
dinnerField: WidgetHandler<DjangoFormsWidgetsCheckboxInput>; | ||
accomodationField: WidgetHandler<DjangoFormsWidgetsCheckboxInput>; | ||
breakfastField: WidgetHandler<DjangoFormsWidgetsCheckboxInput>; | ||
} | ||
|
||
export const AccomodationFieldGroup = ({ | ||
dinnerField, | ||
accomodationField, | ||
breakfastField, | ||
}: AccomodationFieldGroupProps) => { | ||
const [breakfastDisabled, setBreakfastDisabled] = useState( | ||
breakfastField.disabled || !accomodationField.value, | ||
); | ||
|
||
const [dinnerDisabled, setDinnerDisabled] = useState( | ||
dinnerField.disabled || !accomodationField.value, | ||
); | ||
|
||
const onAccomodationChange = ( | ||
field: WidgetHandler<DjangoFormsWidgetsCheckboxInput>, | ||
value: boolean, | ||
) => { | ||
dinnerField.handler(value); | ||
setDinnerDisabled(!value); | ||
|
||
breakfastField.handler(value); | ||
setBreakfastDisabled(!value); | ||
|
||
field.handler(value); | ||
}; | ||
|
||
return ( | ||
<> | ||
<BasicFormField field={dinnerField} disabled={dinnerDisabled} /> | ||
<BasicFormField | ||
field={accomodationField} | ||
onCheckboxChange={onAccomodationChange} | ||
/> | ||
<BasicFormField field={breakfastField} disabled={breakfastDisabled} /> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.