Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lf 4156 create animal batch creation form card #3201

Merged
merged 34 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
395f88e
LF-4156 create new card component
navDhammu Apr 23, 2024
6962ac2
LF-4156 change storybook config to detect story files anywhere inside…
navDhammu Apr 23, 2024
447994e
LF-4156 create component and stories for AddAnimalsFormCard
navDhammu Apr 23, 2024
08d3fc8
LF-4156 fix ts error by updating NumberInput controller props
navDhammu Apr 24, 2024
d06e17a
LF-4156 create separate components for type and breed select
navDhammu Apr 24, 2024
67671e6
LF-4156 fix prop spreading overriding styles prop in react select
navDhammu Apr 24, 2024
a1f951e
LF-4156 create custom menu component for breed select
navDhammu Apr 25, 2024
9adb013
LF-4156 add mock options for type and breed
navDhammu Apr 25, 2024
fa91258
LF-4156 replace useForm with useFormContext
navDhammu Apr 26, 2024
af0c2f6
LF-4156 remove if condition from react select change handler
navDhammu Apr 30, 2024
7549d0d
LF-4156 add className prop to NumberInput and InputBase; adjust width…
navDhammu Apr 30, 2024
d1703ac
LF-4156 remove width:100% from InputBase wrapper
navDhammu Apr 30, 2024
9349371
LF-4156 use max count as useMemo dependancy to re-render sex details …
navDhammu Apr 30, 2024
9c5da14
LF-4156 register checkbox for creating individual profiles; update ho…
navDhammu Apr 30, 2024
6b5f78c
LF-4156 register group name
navDhammu Apr 30, 2024
5f946ca
LF-4156 add click handler to remove button
navDhammu Apr 30, 2024
52c9d9a
LF-4156 add translations
navDhammu Apr 30, 2024
d81487e
LF-4156 conditionally render batch or group name input
navDhammu Apr 30, 2024
c21b524
LF-4156 create stories for cardv2
navDhammu May 2, 2024
a8ba4a8
LF-4156 use Main typography component for card heading
navDhammu May 2, 2024
23da542
LF-4156 change breed select to be disabled if type is not selected
navDhammu May 2, 2024
4158705
LF-4156 fix sex details input not taking full width on mobile
navDhammu May 3, 2024
357cf4f
LF-4156 show search icon in searchable react select
navDhammu May 3, 2024
76d9e7f
Merge branch integration into LF-4156-create-animal-batch-creation-fo…
navDhammu May 3, 2024
fd0817a
LF-4156 remove unused translation and run i18n script
navDhammu May 3, 2024
2fa5c53
LF-4156 remove empty string in jsx
navDhammu May 8, 2024
5915dfa
LF-4156 use constants for form field names
navDhammu May 8, 2024
2e57a34
LF-4156 add license
navDhammu May 8, 2024
91e51c7
LF-4156 add hover state and adjust padding on remove button
navDhammu May 8, 2024
39d9b1f
LF-4156 add border radius on card
navDhammu May 8, 2024
1593538
LF-4156 replace names with constants
navDhammu May 10, 2024
a9883ba
LF-4156 move stories to stories folder
navDhammu May 17, 2024
0212fa0
Revert "LF-4156 change storybook config to detect story files anywher…
navDhammu May 17, 2024
8de2691
LF-4156 fix import
navDhammu May 17, 2024
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
1 change: 1 addition & 0 deletions packages/webapp/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"CLOSE": "Close",
"CONFIRM": "Confirm",
"CONTINUE": "Continue",
"COUNT": "Count",
"CREATE": "Create",
"CREATE_A_TASK": "Create a task",
"DATE": "Date",
Expand Down
12 changes: 12 additions & 0 deletions packages/webapp/public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
{
"ADD_ANIMAL": {
"ADD_TO_INVENTORY": "Add animal to your inventory",
"ANIMALS_TOTAL_one": "{{count}} animal total",
"ANIMALS_TOTAL_other": "{{count}} animals total",
"ANIMALS_UNSPECIFIED_one": "{{count}} unspecified",
"ANIMALS_UNSPECIFIED_other": "{{count}} unspecified",
"BATCH_NAME": "Batch name",
"BATCH_NAME_PLACEHOLDER": "Type in batch name",
"BREED": "Breed",
"BREED_PLACEHOLDER": "Add your animal breed",
"BREED_PLACEHOLDER_DISABLED": "Please select a type first",
"CREATE_INDIVIDUAL_PROFILES": "Create individual animal profiles",
"CREATE_INDIVIDUAL_PROFILES_TOOLTIP": "Select this option if you want to track and manage each animal separately. This allows for detailed records and individualised care plans, all animals will be conveniently grouped. If you don't select 'Create Individual Animal Profiles' you'll create an Animal Batch. This is ideal for\u00a0managing animals collectively. In batch mode, individual animal details are not tracked.",
"GENERAL_DETAILS": "General details",
"GROUP_NAME": "Group name",
"GROUP_NAME_PLACEHOLDER": "Type in group name",
"ORIGIN": "Origin",
"OTHER_DETAILS": "Other details",
"OUT_OF_COUNT_one": "{{animalNumber}} out of {{count}}",
Expand Down Expand Up @@ -43,6 +53,8 @@
"HERE_IS_SUMMARY": "Here is a summary of your added animals:",
"MAIN": "You successfully added {{animalCount}} {{and}} {{batchCount}} to your inventory."
},
"TYPE": "Type",
"TYPE_PLACEHOLDER": "Select the animal type",
"UNIQUE_DETAILS": "Unique details",
"USED_FOR_REPRODUCTION": "Used for reproduction?"
},
Expand Down
1 change: 1 addition & 0 deletions packages/webapp/public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"CLOSE": "Cerrar",
"CONFIRM": "Confirmar",
"CONTINUE": "Continuar",
"COUNT": "MISSING",
"CREATE": "Agregar",
"CREATE_A_TASK": "MISSING",
"DATE": "Fecha",
Expand Down
12 changes: 12 additions & 0 deletions packages/webapp/public/locales/es/translation.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{
"ADD_ANIMAL": {
"ADD_TO_INVENTORY": "MISSING",
"ANIMALS_TOTAL_one": "MISSING",
"ANIMALS_TOTAL_many": "MISSING",
"ANIMALS_TOTAL_other": "MISSING",
"ANIMALS_UNSPECIFIED_one": "MISSING",
"ANIMALS_UNSPECIFIED_many": "MISSING",
"ANIMALS_UNSPECIFIED_other": "MISSING",
"BATCH_NAME": "MISSING",
"BATCH_NAME_PLACEHOLDER": "MISSING",
"BREED": "MISSING",
"BREED_PLACEHOLDER": "MISSING",
"BREED_PLACEHOLDER_DISABLED": "MISSING",
"CREATE_INDIVIDUAL_PROFILES": "MISSING",
"CREATE_INDIVIDUAL_PROFILES_TOOLTIP": "MISSING",
"GENERAL_DETAILS": "MISSING",
"GROUP_NAME": "MISSING",
"GROUP_NAME_PLACEHOLDER": "MISSING",
"ORIGIN": "MISSING",
"OTHER_DETAILS": "MISSING",
"OUT_OF_COUNT_one": "MISSING",
Expand Down Expand Up @@ -44,6 +54,8 @@
"HERE_IS_SUMMARY": "MISSING",
"MAIN": "MISSING"
},
"TYPE": "MISSING",
"TYPE_PLACEHOLDER": "MISSING",
"UNIQUE_DETAILS": "MISSING",
"USED_FOR_REPRODUCTION": "MISSING"
},
Expand Down
1 change: 1 addition & 0 deletions packages/webapp/public/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"CLOSE": "Fermer",
"CONFIRM": "Valider",
"CONTINUE": "Continuer",
"COUNT": "MISSING",
"CREATE": "Créer",
"CREATE_A_TASK": "MISSING",
"DATE": "Date",
Expand Down
12 changes: 12 additions & 0 deletions packages/webapp/public/locales/fr/translation.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{
"ADD_ANIMAL": {
"ADD_TO_INVENTORY": "MISSING",
"ANIMALS_TOTAL_one": "MISSING",
"ANIMALS_TOTAL_many": "MISSING",
"ANIMALS_TOTAL_other": "MISSING",
"ANIMALS_UNSPECIFIED_one": "MISSING",
"ANIMALS_UNSPECIFIED_many": "MISSING",
"ANIMALS_UNSPECIFIED_other": "MISSING",
"BATCH_NAME": "MISSING",
"BATCH_NAME_PLACEHOLDER": "MISSING",
"BREED": "MISSING",
"BREED_PLACEHOLDER": "MISSING",
"BREED_PLACEHOLDER_DISABLED": "MISSING",
"CREATE_INDIVIDUAL_PROFILES": "MISSING",
"CREATE_INDIVIDUAL_PROFILES_TOOLTIP": "MISSING",
"GENERAL_DETAILS": "MISSING",
"GROUP_NAME": "MISSING",
"GROUP_NAME_PLACEHOLDER": "MISSING",
"ORIGIN": "MISSING",
"OTHER_DETAILS": "MISSING",
"OUT_OF_COUNT_one": "MISSING",
Expand Down Expand Up @@ -48,6 +58,8 @@
"HERE_IS_SUMMARY": "MISSING",
"MAIN": "MISSING"
},
"TYPE": "MISSING",
"TYPE_PLACEHOLDER": "MISSING",
"UNIQUE_DETAILS": "MISSING",
"USED_FOR_REPRODUCTION": "MISSING"
},
Expand Down
1 change: 1 addition & 0 deletions packages/webapp/public/locales/pt/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"CLOSE": "Fechar",
"CONFIRM": "Confirmar",
"CONTINUE": "Continuar",
"COUNT": "MISSING",
"CREATE": "Adicionar",
"CREATE_A_TASK": "MISSING",
"DATE": "Data",
Expand Down
12 changes: 12 additions & 0 deletions packages/webapp/public/locales/pt/translation.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
{
"ADD_ANIMAL": {
"ADD_TO_INVENTORY": "MISSING",
"ANIMALS_TOTAL_one": "MISSING",
"ANIMALS_TOTAL_many": "MISSING",
"ANIMALS_TOTAL_other": "MISSING",
"ANIMALS_UNSPECIFIED_one": "MISSING",
"ANIMALS_UNSPECIFIED_many": "MISSING",
"ANIMALS_UNSPECIFIED_other": "MISSING",
"BATCH_NAME": "MISSING",
"BATCH_NAME_PLACEHOLDER": "MISSING",
"BREED": "MISSING",
"BREED_PLACEHOLDER": "MISSING",
"BREED_PLACEHOLDER_DISABLED": "MISSING",
"CREATE_INDIVIDUAL_PROFILES": "MISSING",
"CREATE_INDIVIDUAL_PROFILES_TOOLTIP": "MISSING",
"GENERAL_DETAILS": "MISSING",
"GROUP_NAME": "MISSING",
"GROUP_NAME_PLACEHOLDER": "MISSING",
"ORIGIN": "MISSING",
"OTHER_DETAILS": "MISSING",
"OUT_OF_COUNT_one": "MISSING",
Expand Down Expand Up @@ -48,6 +58,8 @@
"HERE_IS_SUMMARY": "MISSING",
"MAIN": "MISSING"
},
"TYPE": "MISSING",
"TYPE_PLACEHOLDER": "MISSING",
"UNIQUE_DETAILS": "MISSING",
"USED_FOR_REPRODUCTION": "MISSING"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/webapp/src/assets/images/x-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright 2024 LiteFarm.org
* This file is part of LiteFarm.
*
* LiteFarm is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiteFarm is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>.
*/

import { Controller, useFormContext } from 'react-hook-form';

import NumberInput from '../../Form/NumberInput';
import Checkbox from '../../Form/Checkbox';
import SexDetails from '../../Form/SexDetails';
import styles from './styles.module.scss';
import Input from '../../Form/Input';
import Card from '../../CardV2';
import { Main } from '../../Typography';
import TextButton from '../../Form/Button/TextButton';
import { ReactComponent as XIcon } from '../../../assets/images/x-icon.svg';
import { type Details as SexDetailsType } from '../../Form/SexDetails/SexDetailsPopover';
import {
AnimalBreedSelect,
AnimalTypeSelect,
type AnimalBreedSelectProps,
type AnimalTypeSelectProps,
type Option,
} from './AnimalSelect';
import { useTranslation } from 'react-i18next';

const FIELD_NAMES = {
TYPE: 'type',
BREED: 'breed',
SEX_DETAILS: 'sexDetails',
COUNT: 'count',
CREATE_INDIVIDUAL_PROFILES: 'createIndividualProfiles',
GROUP: 'group',
BATCH: 'batch',
} as const;

// Should be moved up to parent component that calls useForm
type FormFields = {
[FIELD_NAMES.TYPE]?: Option;
[FIELD_NAMES.BREED]?: Option;
[FIELD_NAMES.SEX_DETAILS]: SexDetailsType;
[FIELD_NAMES.COUNT]?: number;
[FIELD_NAMES.CREATE_INDIVIDUAL_PROFILES]?: boolean;
[FIELD_NAMES.GROUP]?: string;
[FIELD_NAMES.BATCH]?: string;
};

type AddAnimalsFormCardProps = AnimalTypeSelectProps &
AnimalBreedSelectProps & {
sexDetailsOptions: SexDetailsType;
onIndividualProfilesCheck?: (isChecked: boolean) => void;
onRemoveButtonClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
showRemoveButton?: boolean;
isActive?: boolean;
};

export default function AddAnimalsFormCard({
typeOptions,
breedOptions,
sexDetailsOptions,
onTypeChange,
onIndividualProfilesCheck,
showRemoveButton,
onRemoveButtonClick,
isActive,
SayakaOno marked this conversation as resolved.
Show resolved Hide resolved
}: AddAnimalsFormCardProps) {
const { control, watch, register } = useFormContext<FormFields>();
const { t } = useTranslation();
const watchAnimalCount = watch(FIELD_NAMES.COUNT) || 0;
const watchAnimalType = watch(FIELD_NAMES.TYPE);
const shouldCreateIndividualProfiles = watch(FIELD_NAMES.CREATE_INDIVIDUAL_PROFILES);

return (
<Card className={styles.form} isActive={isActive}>
<div className={styles.formHeader}>
<Main>{t('ADD_ANIMAL.ADD_TO_INVENTORY')}</Main>
{showRemoveButton && (
<TextButton className={styles.removeBtn} onClick={onRemoveButtonClick}>
<XIcon /> {t('common:REMOVE')}
</TextButton>
)}
</div>
<AnimalTypeSelect
name={FIELD_NAMES.TYPE}
control={control}
typeOptions={typeOptions}
onTypeChange={onTypeChange}
/>
<AnimalBreedSelect
name={FIELD_NAMES.BREED}
control={control}
breedOptions={breedOptions}
isTypeSelected={!!watchAnimalType}
/>

<div className={styles.countAndSexDetailsWrapper}>
<NumberInput
name={FIELD_NAMES.COUNT}
control={control}
defaultValue={0}
label={t('common:COUNT')}
className={styles.countInput}
allowDecimal={false}
showStepper
/>
<Controller
name={FIELD_NAMES.SEX_DETAILS}
control={control}
render={({ field }) => (
<SexDetails
initialDetails={sexDetailsOptions}
maxCount={watchAnimalCount}
onConfirm={(details) => field.onChange(details)}
/>
)}
/>
</div>
<Checkbox
label={t('ADD_ANIMAL.CREATE_INDIVIDUAL_PROFILES')}
tooltipContent={t('ADD_ANIMAL.CREATE_INDIVIDUAL_PROFILES_TOOLTIP')}
hookFormRegister={register(FIELD_NAMES.CREATE_INDIVIDUAL_PROFILES)}
onChange={(e) => onIndividualProfilesCheck?.((e.target as HTMLInputElement).checked)}
/>
{shouldCreateIndividualProfiles ? (
// @ts-ignore
<Input
label={t('ADD_ANIMAL.GROUP_NAME')}
optional
placeholder={t('ADD_ANIMAL.GROUP_NAME_PLACEHOLDER')}
hookFormRegister={register(FIELD_NAMES.GROUP)}
/>
) : (
// @ts-ignore
<Input
Copy link
Collaborator Author

@navDhammu navDhammu Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Input is handling text inputs, number inputs, date pickers, and passwords inputs all in one. It might be good to extract those out into different components and also use typescript to avoid ts-ignore.

Also the placeholder text appears to be darker than the one in react select.

label={t('ADD_ANIMAL.BATCH_NAME')}
optional
placeholder={t('ADD_ANIMAL.BATCH_NAME_PLACEHOLDER')}
hookFormRegister={register(FIELD_NAMES.BATCH)}
/>
)}
</Card>
);
}
Loading
Loading