Skip to content

Commit c55cd39

Browse files
jotahdavidfilipepacheco
authored andcommitted
Campo de quantidade adicionado quando adicionar suprimento a um abrigo (SOS-RS#46)
* feat(shelter-supply): input to add quantity supply * feat(shelter-supply): show quantity supply at Shelter page and EditShelter page * resolve conflict --------- Co-authored-by: Lipe <[email protected]>
1 parent 7a7c344 commit c55cd39

File tree

13 files changed

+54
-20
lines changed

13 files changed

+54
-20
lines changed

src/components/Chip/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export type ChipVariant = 'info' | 'success' | 'warn' | 'danger';
33
export interface IChipProps extends React.ComponentPropsWithoutRef<'div'> {
44
label: string;
55
variant?: ChipVariant;
6+
quantity?: number;
67
}

src/hooks/useShelter/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface IUseShelterData {
2323

2424
export interface IUseShelterDataSupply {
2525
priority: number;
26+
quantity?: number | null;
2627
supply: IUseShelterDataSupplyData;
2728
}
2829

src/hooks/useShelters/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface IUseSheltersDataSupplyData {
3030
};
3131
priority: number;
3232
tags: ShelterTagType[];
33+
quantity?: number | null;
3334
}
3435

3536
export interface IUseShelterOptions {

src/pages/CreateSupply/CreateSupply.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const CreateSupply = () => {
4747
validationSchema: Yup.object().shape({
4848
shelterId: Yup.string().required('Este campo deve ser preenchido'),
4949
name: Yup.string().required('Este campo deve ser preenchido'),
50+
quantity: Yup.number().typeError('Insira um valor númerico').moreThan(0, 'O valor tem que ser maior do que 0').optional(),
5051
priority: Yup.string().required('Este campo deve ser preenchido'),
5152
supplyCategoryId: Yup.string().required('Este campo deve ser preenchido'),
5253
}),
@@ -59,6 +60,7 @@ const CreateSupply = () => {
5960
await ShelterSupplyServices.create({
6061
supplyId: resp.data.id,
6162
priority: +values.priority,
63+
quantity: Number(values.quantity) || null,
6264
shelterId,
6365
});
6466
clearCache(false);
@@ -134,6 +136,12 @@ const CreateSupply = () => {
134136
</SelectContent>
135137
</Select>
136138
</div>
139+
<TextField
140+
label="Quantidade"
141+
{...getFieldProps('quantity')}
142+
error={!!errors.quantity}
143+
helperText={errors.quantity}
144+
/>
137145
<div className="flex flex-col w-full">
138146
<label className="text-muted-foreground">Prioridade</label>
139147
<Select

src/pages/EditShelterSupply/EditShelterSupply.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ const EditShelterSupply = () => {
185185
return {
186186
id: v.id,
187187
name: v.name,
188+
quantity: supply?.quantity,
188189
priority: supply?.priority,
189190
};
190191
});

src/pages/EditShelterSupply/components/SupplyRow/SupplyRow.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const SupplyRow = (props: ISupplyRowProps) => {
1313
<SupplyRowInfo
1414
key={idy}
1515
name={item.name}
16+
quantity={item.quantity}
1617
priority={item.priority ?? SupplyPriority.NotNeeded}
1718
onClick={() => (onClick ? onClick(item) : undefined)}
1819
/>

src/pages/EditShelterSupply/components/SupplyRow/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { SupplyPriority } from '@/service/supply/types';
33
export interface ISupplyRowItemProps {
44
id: string;
55
name: string;
6+
quantity?: number | null;
67
priority?: SupplyPriority;
78
}
89

src/pages/EditShelterSupply/components/SupplyRowInfo/SupplyRowInfo.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import { useMemo } from 'react';
33
import { CircleStatus } from '@/components';
44
import { ISupplyRowInfoProps } from './types';
55
import { getSupplyPriorityProps } from '@/lib/utils';
6+
import { Badge } from '@/components/ui/badge';
67

78
const SupplyRowInfo = (props: ISupplyRowInfoProps) => {
8-
const { name, priority, onClick } = props;
9+
const { name, priority, quantity, onClick } = props;
910

1011
const { className, label } = useMemo(
1112
() => getSupplyPriorityProps(priority),
@@ -21,6 +22,9 @@ const SupplyRowInfo = (props: ISupplyRowInfoProps) => {
2122
<div className="flex justify-end items-center gap-2">
2223
<CircleStatus className={className} />
2324
<p className="text-muted-foreground text-nowrap pl-1">{label}</p>
25+
{quantity && (
26+
<Badge className="bg-gray-700">{quantity}</Badge>
27+
)}
2428
</div>
2529
</div>
2630
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export interface ISupplyRowInfoProps {
22
name: string;
3+
quantity?: number | null;
34
priority: number;
45
onClick?: () => void;
56
}

src/pages/Shelter/Shelter.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ const Shelter = () => {
3737
.sort(([a], [b]) => (+a > +b ? -1 : 1))
3838
.map(([key, values]) => ({
3939
priority: +key,
40-
tags: values.map((v) => ({ label: v.supply.name, value: v.supply.id })),
40+
tags: values.map((v) => ({
41+
label: v.supply.name,
42+
value: v.supply.id,
43+
quantity: v.quantity,
44+
})),
4145
}));
4246
}, [shelter?.shelterSupplies]);
4347
const { availability, className: availabilityClassName } =

0 commit comments

Comments
 (0)