Skip to content

Commit

Permalink
Merge branch 'develop' into typo-in-encounter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahendar0701 authored Jan 29, 2025
2 parents 9c2ef6b + 881610a commit b81346d
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 55 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
uses: actions/cache@v4
Expand All @@ -45,7 +45,7 @@ jobs:
${{ runner.os }}-buildx-test-
- name: Test build
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
${{ runner.os }}-buildx-build-
- name: Build and push image
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
Expand Down
94 changes: 47 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"uuid": "^11.0.2",
"vite": "^5.4.10",
"vite-plugin-checker": "^0.8.0",
"vite-plugin-pwa": "^0.20.5",
"vite-plugin-pwa": "^0.21.0",
"vite-plugin-static-copy": "^2.0.0",
"zod": "^3.23.8"
},
Expand Down
13 changes: 13 additions & 0 deletions src/components/Facility/FacilityForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ interface FacilityProps {
onSubmitSuccess?: () => void;
}

function extractHierarchyLevels(org: Organization | undefined): Organization[] {
const levels: Organization[] = [];
while (org && org.level_cache >= 0) {
levels.unshift(org as Organization);
org = org.parent as Organization | undefined;
}
return levels;
}

export default function FacilityForm(props: FacilityProps) {
const { t } = useTranslation();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -177,7 +186,11 @@ export default function FacilityForm(props: FacilityProps) {

useEffect(() => {
if (facilityId) return;
const orgLevels = extractHierarchyLevels(org);
const districtMatch =
districtOrg && orgLevels.some((level) => level.name === districtOrg.name);
const levels: Organization[] = [];
if (districtMatch) return;
if (stateOrg) levels.push(stateOrg);
if (districtOrg) levels.push(districtOrg);
if (!stateOrg && !districtOrg && org) levels.push(org);
Expand Down
34 changes: 30 additions & 4 deletions src/components/Users/UserForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
Expand Down Expand Up @@ -38,18 +38,26 @@ import mutate from "@/Utils/request/mutate";
import query from "@/Utils/request/query";
import validators from "@/Utils/validators";
import GovtOrganizationSelector from "@/pages/Organization/components/GovtOrganizationSelector";
import { Organization } from "@/types/organization/organization";
import organizationApi from "@/types/organization/organizationApi";
import { CreateUserModel, UpdateUserModel, UserBase } from "@/types/user/user";
import userApi from "@/types/user/userApi";

interface Props {
onSubmitSuccess?: (user: UserBase) => void;
existingUsername?: string;
organizationId?: string;
}

export default function UserForm({ onSubmitSuccess, existingUsername }: Props) {
export default function UserForm({
onSubmitSuccess,
existingUsername,
organizationId,
}: Props) {
const { t } = useTranslation();
const isEditMode = !!existingUsername;
const queryClient = useQueryClient();
const [selectedLevels, setSelectedLevels] = useState<Organization[]>([]);

const userFormSchema = z
.object({
Expand Down Expand Up @@ -257,6 +265,20 @@ export default function UserForm({ onSubmitSuccess, existingUsername }: Props) {
}
};

const { data: org } = useQuery({
queryKey: ["organization", organizationId],
queryFn: query(organizationApi.get, {
pathParams: { id: organizationId },
}),
enabled: !!organizationId,
});

useEffect(() => {
const levels: Organization[] = [];
if (org) levels.push(org);
setSelectedLevels(levels);
}, [org, organizationId]);

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
Expand Down Expand Up @@ -575,8 +597,12 @@ export default function UserForm({ onSubmitSuccess, existingUsername }: Props) {
<FormItem>
<FormControl>
<GovtOrganizationSelector
value={field.value}
onChange={field.onChange}
{...field}
value={form.watch("geo_organization")}
selected={selectedLevels}
onChange={(value) =>
form.setValue("geo_organization", value)
}
required={!isEditMode}
/>
</FormControl>
Expand Down
1 change: 1 addition & 0 deletions src/pages/Organization/OrganizationUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default function OrganizationUsers({ id, navOrganizationId }: Props) {
onUserCreated={(user) => {
updateQuery({ sheet: "link", username: user.username });
}}
organizationId={id}
/>
<LinkUserSheet
organizationId={id}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/Organization/components/AddUserSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ interface AddUserSheetProps {
open: boolean;
setOpen: (open: boolean) => void;
onUserCreated?: (user: UserBase) => void;
organizationId?: string;
}

export default function AddUserSheet({
open,
setOpen,
onUserCreated,
organizationId,
}: AddUserSheetProps) {
const { t } = useTranslation();
return (
Expand All @@ -50,6 +52,7 @@ export default function AddUserSheet({
setOpen(false);
onUserCreated?.(user);
}}
organizationId={organizationId}
/>
</div>
</SheetContent>
Expand Down

0 comments on commit b81346d

Please sign in to comment.