Skip to content

Commit

Permalink
Everything but formselect
Browse files Browse the repository at this point in the history
  • Loading branch information
x183 committed May 25, 2023
1 parent 992eb31 commit 27d23e8
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 34 deletions.
63 changes: 63 additions & 0 deletions frontend/src/components/AddGame/AddGame.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@import 'src/styles/variables';
.addGameContainer {
border: $border;
border-radius:$margin-smallest;
display: flex;
flex-direction: column;
min-height: 20rem;
width: 20rem;
align-self: center;
top: $margin-medium;
background-color: $color-bright;
position:absolute;
z-index:3;
padding: 1rem;
}
.button {
border: none;
border-radius: 999999rem; // Pill shaped
background-color: $color-accent;
color: $text-bright;
padding: 0.5rem 1rem;
box-shadow: $shadow;
cursor: pointer;
transition: all 200ms ease-in;
align-self: center;

&:hover {
filter: brightness(1.2);
}

&:active {
box-shadow: none;
filter: brightness(0.8);
}

&:disabled {
filter: brightness(0.8);
box-shadow: none;
cursor: default;
}
}

.lightBox {
background-color: rgba($color-dark, 0.5);
position: fixed;
top: 0;
left: 0;
right:0;
bottom: 0;
z-index: 2;
}

.title {
font-size: $text-big;
font-weight: bold;
align-self: center;
}

.divider {
height: 1px;
width: 100%;
background-color: $color-dark;
}
33 changes: 18 additions & 15 deletions frontend/src/components/AddGame/AddGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import { FieldErrors, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import FormInput from '../Forms/FormInput/FormInput';
import FormTextArea from '../Forms/FormTextArea/FormTextArea';
import FormSelect from '../Forms/FromSelect/FormSelect';
import FormSelect from '../Forms/FormSelect/FormSelect';
import styles from './AddGame.module.scss';

interface AddGameProps {}
interface AddGameProps {
showSelf: (b: boolean) => void;
}

const addGameSchema = z
.object({
Expand Down Expand Up @@ -52,7 +55,7 @@ const addGameSchema = z

type AddGameForm = z.infer<typeof addGameSchema>;

const AddGame: FC<AddGameProps> = () => {
const AddGame: FC<AddGameProps> = ({ showSelf }) => {
const { data, error, isLoading } = usePlatforms();

const {
Expand Down Expand Up @@ -114,7 +117,15 @@ const AddGame: FC<AddGameProps> = () => {

return (
<>
<form onSubmit={handleSubmit(submitHandler, invalidFormHandler)}>

<div className={styles.lightBox} onClick={() => {
showSelf(false);
}} />
<form className={styles.addGameContainer} onSubmit={() => {
handleSubmit(submitHandler, invalidFormHandler);
}}>
<h2 className={styles.title}>Add new game</h2>
<div className={styles.divider} />
<FormInput
label="Name of the game"
name="name"
Expand All @@ -123,15 +134,13 @@ const AddGame: FC<AddGameProps> = () => {
error={errors.name?.message}
/>
<br />

<FormTextArea
label="Description fo the game"
label="Description of the game"
register={register}
name="description"
error={errors.description?.message}
/>
<br />

<FormSelect
label="Platform"
options={data.map((platform) => {
Expand All @@ -143,7 +152,6 @@ const AddGame: FC<AddGameProps> = () => {
error={errors.platform?.message}
/>
<br />

<FormInput
label="Release date"
name="releaseDate"
Expand All @@ -153,7 +161,6 @@ const AddGame: FC<AddGameProps> = () => {
error={errors.releaseDate?.message}
/>
<br />

<FormInput
label="Expected playtime"
name="playtime"
Expand All @@ -163,7 +170,6 @@ const AddGame: FC<AddGameProps> = () => {
error={errors.playtime?.message}
/>
<br />

<FormInput
label="Minimum number of players"
name="playerMin"
Expand All @@ -173,7 +179,6 @@ const AddGame: FC<AddGameProps> = () => {
error={errors.playerMin?.message}
/>
<br />

<FormInput
label="Maximum number of players"
name="playerMax"
Expand All @@ -183,21 +188,19 @@ const AddGame: FC<AddGameProps> = () => {
error={errors.playerMax?.message}
/>
<br />

<FormInput
label="Location of the game"
name="location"
type="text"
register={register}
error={errors.location?.message}
/>
<br />

{errors.root ? <p>Error: {errors.root.message}</p> : null}

<input type="submit" disabled={postLoading} value="Submit" />
<input className={styles.button} type="submit" disabled={postLoading} value="Submit" />
</form>
</>
</ >
);
};

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/AddSuggestion/AddSuggestion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as z from 'zod';
import { toast } from 'react-toastify';
import FormInput from '../Forms/FormInput/FormInput';
import FormTextArea from '../Forms/FormTextArea/FormTextArea';
import FormSelect from '../Forms/FromSelect/FormSelect';
import FormSelect from '../Forms/FormSelect/FormSelect';
import { useAddGameSuggestion } from '@/src/hooks/api/useAddGameSuggestion';
import { usePlatforms } from '@/src/hooks/api/usePlatforms';

Expand Down
23 changes: 23 additions & 0 deletions frontend/src/components/Forms/FormInput/FormInput.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@import 'src/styles/variables';
.container {
display: flex;
flex-direction: column;
margin: 0 $margin-small;
padding: $margin-small 0;
}

.inputBox{
border:$border;
border-radius: $margin-smallest;
padding: $margin-smallest;
margin-top: $margin-smallest;
box-shadow: $shadow;

}

.label {
font-size: $text-normal;
font-weight: bold;
display:block;
align-self:center;
}
7 changes: 4 additions & 3 deletions frontend/src/components/Forms/FormInput/FormInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { FC, InputHTMLAttributes } from 'react';
import { UseFormRegister, RegisterOptions } from 'react-hook-form';
import styles from './FormInput.module.scss';

interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
name: string;
Expand All @@ -21,9 +22,9 @@ const FormInput: FC<InputProps> = ({
...rest
}) => {
return (
<div className={wrapperClass}>
{label && <label htmlFor={name}>{label}</label>}
<input
<div className={styles.container}>
{label && <label htmlFor={name} className={styles.label} >{label}</label>}<br />
<input className={styles.inputBox}
aria-invalid={error ? 'true' : 'false'}
{...(register ? register(name, registerOptions) : {})}
{...rest}
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/components/Forms/FormSelect/FormSelect.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import 'src/styles/variables';

.box {
display: flex;
flex-direction: column;
margin: 0 $margin-small;
padding: $margin-small 0;
}

.inputBox{
border:$border;
border-radius: $margin-smallest;
padding: $margin-smallest;
margin-top: $margin-smallest;
box-shadow: $shadow;
resize: vertical;
}

.label {
font-size: $text-normal;
font-weight: bold;
display:block;
align-self:center;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Control
} from 'react-hook-form';
import Option from 'react-select/dist/declarations/src/components/Option';
import styles from './FormSelect.module.scss';

interface Option {
value: string;
Expand All @@ -19,7 +20,6 @@ interface SelectProps extends Props {
error?: string;
options: Option[];
control?: Control<any, any>;
wrapperClass?: string;
value?: Option;
}

Expand All @@ -29,19 +29,19 @@ const FormSelect: FC<SelectProps> = ({
label,
control,
options,
wrapperClass,
value: defaultValue,
...rest
}) => {
return (
<div className={wrapperClass}>
{label && <label htmlFor={name}>{label}</label>}
<div className={styles.box}>
{label && <label className={styles.label} htmlFor={name}>{label}</label>}
<Controller
control={control}
defaultValue={defaultValue}
name={name}
render={({ field: { onChange, value, ref } }) => (
<Select
className={styles.inputBox}
ref={ref}
value={
Array.isArray(value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@import 'src/styles/variables';

.box {
display: flex;
flex-direction: column;
margin: 0 $margin-small;
padding: $margin-small 0;
}

.inputBox{
border:$border;
border-radius: $margin-smallest;
padding: $margin-smallest;
margin-top: $margin-smallest;
box-shadow: $shadow;
resize: vertical;
}

.label {
font-size: $text-normal;
font-weight: bold;
display:block;
align-self:center;
}
9 changes: 4 additions & 5 deletions frontend/src/components/Forms/FormTextArea/FormTextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { FC, TextareaHTMLAttributes } from 'react';
import { UseFormRegister, FieldValues, RegisterOptions } from 'react-hook-form';
import styles from './FormTextArea.module.scss';

interface TextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
name: string;
label?: string;
error?: string;
register?: UseFormRegister<any>;
registerOptions?: RegisterOptions;
wrapperClass?: string;
className?: string;
}

Expand All @@ -17,13 +17,12 @@ const FormTextArea: FC<TextAreaProps> = ({
name,
error,
label,
wrapperClass,
...rest
}) => {
return (
<div className={wrapperClass}>
{label && <label htmlFor={name}>{label}</label>}
<textarea
<div className={styles.box}>
{label && <label className={styles.label} htmlFor={name}>{label}</label>}
<textarea className={styles.inputBox}
aria-invalid={error ? 'true' : 'false'}
{...(register ? register(name, registerOptions) : {})}
{...rest}
Expand Down
Loading

0 comments on commit 27d23e8

Please sign in to comment.