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

Revamp Asset Create/Update Workflow using ShadCN, React-Hook-Form, and TanStack Query #9192

Closed
Closed
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3b41347
fix api call issue #9198
rajku-dev Nov 24, 2024
20634fb
make assetCreate page to use Form component
rajku-dev Nov 25, 2024
ea14bd0
wrap form in AssetCreate page using Form component
rajku-dev Nov 25, 2024
3c1a2ac
pass additionalButtons prop
rajku-dev Nov 26, 2024
29aa629
edit handleOnCancel
rajku-dev Nov 26, 2024
c5312fb
add create asset and add more button
rajku-dev Nov 28, 2024
e602030
add translation and use PhoneNumberValidator
rajku-dev Nov 30, 2024
28affcc
Merge branch 'issue/9189/edit-assetcreate' of https://github.com/rajk…
rajku-dev Dec 20, 2024
144a934
Merge branch 'develop' into issue/9189/edit-assetcreate
rajku-dev Dec 20, 2024
10c119f
Merge branch 'develop' into issue/9189/edit-assetcreate
rajku-dev Dec 23, 2024
5387f60
use shadcn form in AssetCreate with other shadcn components | add dir…
rajku-dev Dec 23, 2024
eca4c45
fix error in calendar
rajku-dev Dec 23, 2024
5866149
add phone-input component
rajku-dev Dec 23, 2024
f1830ec
refine phone/toll validation
rajku-dev Dec 24, 2024
4d170d3
restore LocationSelect
rajku-dev Dec 24, 2024
4bded8d
Merge branch 'develop' into issue/9189/edit-assetcreate
rajku-dev Dec 24, 2024
203f1ef
Merge branch 'develop' into issue/9189/edit-assetcreate
rajku-dev Dec 24, 2024
4f24c9b
Merge branch 'develop' into issue/9189/edit-assetcreate
rajku-dev Dec 24, 2024
2fbd98c
fix auto label conflicts
rajku-dev Dec 24, 2024
8a4532a
Merge branch 'develop' into issue/9189/edit-assetcreate
rajku-dev Dec 25, 2024
7e13010
fix package-lock.json lint error
rajku-dev Dec 25, 2024
06b1f88
Replace existing queries with useQuery and useMutation hooks
rajku-dev Dec 29, 2024
5ab7a9d
Merge branch 'develop' into issue/9189/edit-assetcreate
rajku-dev Dec 29, 2024
080fa41
fix package-lock.json lint
rajku-dev Dec 29, 2024
ea8f42f
fix auto-label
rajku-dev Dec 29, 2024
2e537b7
reinstall dependencies
rajku-dev Dec 29, 2024
aaee965
fix unexpected behaviour of Location/Asset-Class Select Fields
rajku-dev Dec 29, 2024
2b09246
remove console logs
rajku-dev Dec 29, 2024
999fe14
drop `AssetLocationSelect`
rajku-dev Dec 29, 2024
70d52bb
switch to old `DateFormField`
rajku-dev Dec 30, 2024
760b363
increase font | add asterisk | fix asset-class issue
rajku-dev Dec 30, 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
507 changes: 495 additions & 12 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@googlemaps/typescript-guards": "^2.0.3",
"@headlessui/react": "^2.2.0",
"@hello-pangea/dnd": "^17.0.0",
"@hookform/resolvers": "^3.9.1",
"@pnotify/core": "^5.2.0",
"@pnotify/mobile": "^5.2.0",
"@radix-ui/react-dialog": "^1.1.4",
Expand All @@ -64,7 +65,9 @@
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-scroll-area": "^1.2.0",
"@radix-ui/react-select": "^2.1.4",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-switch": "^1.1.2",
"@radix-ui/react-toast": "^1.2.4",
"@radix-ui/react-tooltip": "^1.1.6",
"@sentry/browser": "^8.45.1",
Expand All @@ -80,6 +83,7 @@
"cmdk": "^1.0.4",
"cross-env": "^7.0.3",
"cypress": "^13.17.0",
"date-fns": "^4.1.0",
"dayjs": "^1.11.13",
"echarts": "^5.5.1",
"echarts-for-react": "^3.0.2",
Expand All @@ -88,16 +92,20 @@
"i18next": "^23.16.4",
"i18next-browser-languagedetector": "^8.0.2",
"i18next-http-backend": "^3.0.1",
"lucide-react": "^0.469.0",
"postcss-loader": "^8.1.1",
"qrcode.react": "^4.1.0",
"raviger": "^4.1.2",
"react": "18.3.1",
"react-copy-to-clipboard": "^5.1.0",
"react-day-picker": "^9.4.4",
"react-dom": "18.3.1",
"react-google-recaptcha": "^3.1.0",
"react-hook-form": "^7.54.2",
"react-i18next": "^15.1.3",
"react-infinite-scroll-component": "^6.1.0",
"react-pdf": "^9.2.1",
"react-phone-number-input": "^3.4.10",
"react-webcam": "^7.2.0",
"tailwind-merge": "^2.5.5",
"tailwindcss-animate": "^1.0.7",
Expand Down Expand Up @@ -152,7 +160,7 @@
"vite-plugin-checker": "^0.8.0",
"vite-plugin-pwa": "^0.20.5",
"vite-plugin-static-copy": "^2.0.0",
"zod": "^3.23.8"
"zod": "^3.24.1"
},
"browserslist": {
"production": [
Expand Down
82 changes: 82 additions & 0 deletions src/components/Common/AssetLocationSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";

import routes from "@/Utils/request/api";
import useTanStackQueryInstead from "@/Utils/request/useQuery";

interface LocationSelectProps {
name: string;
disabled?: boolean;
margin?: string;
errors?: string;
className?: string;
searchAll?: boolean;
multiple?: boolean;
facilityId: string;
showAll?: boolean;
selected: string | string[] | null;
setSelected: (selected: string | string[] | null) => void;
errorClassName?: string;
bedIsOccupied?: boolean;
disableOnOneOrFewer?: boolean;
}

export const LocationSelect = (props: LocationSelectProps) => {
const { data, loading } = useTanStackQueryInstead(
routes.listFacilityAssetLocation,
{
query: {
limit: 14,
bed_is_occupied:
props.bedIsOccupied === undefined ? undefined : !props.bedIsOccupied,
},
pathParams: {
facility_external_id: props.facilityId,
},
prefetch: props.facilityId !== undefined,
},
);

if (props.disableOnOneOrFewer && data && data.count <= 1) {
props = { ...props, disabled: true };
}

const handleSelectChange = (value: string) => {
props.setSelected(value);
};
console.log("Selected", props.selected);
return (
<div className={props.className}>
<Select
disabled={props.disabled || loading}
onValueChange={handleSelectChange}
value={props.selected as string}
>
<SelectTrigger className={props.errorClassName}>
<SelectValue placeholder="Search by location name">
{data?.results?.find((option) => option.id === props.selected)
?.name || "Search by location name"}
</SelectValue>
</SelectTrigger>
<SelectContent>
{data?.results?.length ? (
data.results.map((option: { id: string; name: string }) => (
<SelectItem key={option.id} value={option.id}>
{option.name}
</SelectItem>
))
) : (
<SelectItem disabled value="No options available">
{loading ? "Loading..." : "No options available"}
</SelectItem>
)}
</SelectContent>
</Select>
</div>
);
};
Loading