Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions frontend/src/app/PackForm/PackForm.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,8 +10,7 @@ import { getPackPath } from "routes";
import { PackFormSpecs } from "./types";
import { DurationUnit } from "enums";
import { Item, PackItem } from "types/item";
import { Pack } from "types/pack";
import { BasePack } from "types/pack";
import { Pack, BasePack, PackConstants } from "types/pack";

import { durationUnitOptions, genderOptions } from "lib/utils/form";

Expand DownExpand Up@@ -174,13 +173,15 @@ const PackForm: React.FC<PackFormSpecs.Props> = ({ history, packId, getPack, exp
error={wasSubmitted && !!errors.title}
errorMsg={errors.title}
value={values.title}
allowedLength={PackConstants.title}
onChange={v => setFieldValue('title', v)}/>

<Textarea label="Field Notes"
placeholder="Additional notes about this trip..."
value={values.description || ''}
onChange={v => setFieldValue('description', v)}
last={true}/>
last={true}
allowedLength={PackConstants.description}/>
</div>
<div className="third">
<Row gutter={8}>
Expand All@@ -207,6 +208,7 @@ const PackForm: React.FC<PackFormSpecs.Props> = ({ history, packId, getPack, exp
</Row>
<Input label="Temp Range"
placeholder="43° - 81° F"
allowedLength={PackConstants.temp_range}
value={values.temp_range || ''}
onChange={v => setFieldValue('temp_range', v)}
/>
Expand All@@ -217,6 +219,7 @@ const PackForm: React.FC<PackFormSpecs.Props> = ({ history, packId, getPack, exp
value={values.season || ''}
onChange={v => setFieldValue('season', v)}
last={true}
allowedLength={PackConstants.season}
/>
</Col>
<Col span={12}>
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/app/components/FormFields/Input.tsx
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
import * as React from 'react';
import { ChangeEvent } from "react";

import { Input } from './styles';
import { Input, CharacterCounter } from './styles';
import { SharedInputProps } from './types';
import { InputContainer } from './utils';


interface InputProps extends SharedInputProps {
value: string | number;
onChange: (value: string | number) => void;
autocomplete?: string;
type?: 'text' | 'number' | 'url' | 'password';
placeholder?: string;
allowedLength?: number;
}

const FormInput: React.FC<InputProps> = ({ onChange, label, error, errorMsg, tip, last, style, ...props }) => {
Expand All@@ -20,6 +22,11 @@ const FormInput: React.FC<InputProps> = ({ onChange, label, error, errorMsg, tip
return (
<InputContainer {...{ error, errorMsg, label, tip, last, style }}>
<Input {...props} onChange={handleChange}/>
{props.allowedLength && props.allowedLength > 0 &&
<CharacterCounter
className={`${props.value.toString().length > props.allowedLength ? "full": ""}`}>
{props.value.toString().length}/{props.allowedLength}
</CharacterCounter>}
</InputContainer>
);
};
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/app/components/FormFields/Textarea.tsx
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
import * as React from 'react';
import { ChangeEvent } from "react";

import { TextareaInput } from './styles';
import { TextareaInput, CharacterCounter } from './styles';
import { SharedInputProps } from './types';
import { InputContainer } from './utils';

interface TextareaProps extends SharedInputProps {
value: string | number;
onChange: (value: string | number) => void;
placeholder?: string;
allowedLength?: number;
}

const Textarea: React.FC<TextareaProps> = ({ onChange, label, error, errorMsg, last, tip, ...props }) => {
Expand All@@ -18,6 +19,11 @@ const Textarea: React.FC<TextareaProps> = ({ onChange, label, error, errorMsg, l
return (
<InputContainer {...{error, errorMsg, label, tip, last}}>
<TextareaInput {...props} onChange={handleChange}/>
{props.allowedLength && props.allowedLength > 0 &&
<CharacterCounter
className={`${props.value.toString().length > props.allowedLength ? "full": ""}`}>
{props.value.toString().length}/{props.allowedLength}
</CharacterCounter>}
</InputContainer>
);
};
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/app/components/FormFields/styles.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,4 +108,11 @@ export const selectStyles: StylesConfig = {
...p,
color: '#ccc'
})
};
};

export const CharacterCounter = styled.small`
float: right;
&.full {
color:red;
}
`;
5 changes: 4 additions & 1 deletion frontend/src/app/components/ItemForm/ItemForm.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import { Row, Col, Button } from "antd";
import { Input, Select, SelectCreatable, Option } from '../FormFields';

import { AppContext } from 'AppContext';
import { CreateItem } from "types/item";
import { CreateItem, ItemConstants } from "types/item";
import { FormSpecs } from "./types";

import withApi from 'app/components/higher-order/with-api';
Expand DownExpand Up@@ -78,6 +78,7 @@ const ItemForm: React.FC<FormSpecs.Props> = ({ createItem, exportCsv, onSubmit }
error={wasSubmitted && !!errors.name}
placeholder="Backpack, Compass, etc..."
onChange={v => setFieldValue('name', v)}
allowedLength={ItemConstants.name}
/>
<SelectCreatable
label="Category"
Expand All@@ -99,6 +100,7 @@ const ItemForm: React.FC<FormSpecs.Props> = ({ createItem, exportCsv, onSubmit }
value={values.product_name || ''}
placeholder="Osprey Renn 65"
onChange={v => setFieldValue('product_name', v)}
allowedLength={ItemConstants.product_name}
/>
<Row gutter={8}>
<Col span={16}>
Expand DownExpand Up@@ -134,6 +136,7 @@ const ItemForm: React.FC<FormSpecs.Props> = ({ createItem, exportCsv, onSubmit }
type="url"
placeholder="https://osprey.com"
onChange={v => setFieldValue('product_url', v)}
allowedLength={ItemConstants.product_url}
/>
<Button onClick={submitForm}
disabled={isSubmitting}
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/types/item.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,4 +51,10 @@ export interface PackItemAttr {

export interface PackItem extends Item {
packItem: PackItemAttr;
}

export enum ItemConstants {
name = 200,
product_name = 500,
product_url = 500
}
7 changes: 7 additions & 0 deletions frontend/src/types/pack.ts
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,3 +34,10 @@ export interface CreatePack extends BasePack {
export type PackOverview = Omit<Pack, 'items'> & {
itemCount: number;
}

export enum PackConstants {
title = 300,
description = 2000,
temp_range = 255,
season = 255
}