Skip to content

Commit

Permalink
Merge branch 'develop' into issues/9043/sidebar-collapse-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alok authored Nov 27, 2024
2 parents 6383d75 + 5329457 commit 116fd93
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
2 changes: 1 addition & 1 deletion package-lock.json

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

3 changes: 3 additions & 0 deletions src/Utils/request/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ export default async function request<TData, TBody>(
return result;
} catch (error: any) {
result = { error, res: undefined, data: undefined };
if (error.name === "AbortError") {
return result;
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Utils/request/useMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import { mergeRequestOptions } from "@/Utils/request/utils";

export default function useMutation<TData, TBody>(
route: MutationRoute<TData, TBody>,
options: RequestOptions<TData>,
options: RequestOptions<TData, TBody>,
) {
const [response, setResponse] = React.useState<RequestResult<TData>>();
const [isProcessing, setIsProcessing] = React.useState(false);

const controllerRef = React.useRef<AbortController>();

const runQuery = React.useCallback(
async (overrides?: RequestOptions<TData>) => {
async (overrides?: RequestOptions<TData, TBody>) => {
controllerRef.current?.abort();

const controller = new AbortController();
Expand All @@ -31,8 +31,10 @@ export default function useMutation<TData, TBody>(

setIsProcessing(true);
const response = await request(route, { ...resolvedOptions, controller });
setResponse(response);
setIsProcessing(false);
if (response.error?.name !== "AbortError") {
setResponse(response);
setIsProcessing(false);
}
return response;
},
[route, JSON.stringify(options)],
Expand Down
6 changes: 4 additions & 2 deletions src/Utils/request/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export default function useQuery<TData>(

setLoading(true);
const response = await request(route, { ...resolvedOptions, controller });
setResponse(response);
setLoading(false);
if (response.error?.name !== "AbortError") {
setResponse(response);
setLoading(false);
}
return response;
},
[route, JSON.stringify(options)],
Expand Down
3 changes: 0 additions & 3 deletions src/components/Facility/ConsultationDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,6 @@ export const ConsultationDetails = (props: any) => {
</div>
<SelectedTab {...consultationTabProps} />
</div>
<div className="px-3 pb-3 md:px-6 md:pb-6">
<SelectedTab {...consultationTabProps} />
</div>
</div>

<DoctorVideoSlideover
Expand Down
46 changes: 24 additions & 22 deletions src/components/Users/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import request from "@/Utils/request/request";
import uploadFile from "@/Utils/request/uploadFile";
import useQuery from "@/Utils/request/useQuery";
import {
classNames,
dateQueryString,
formatDate,
formatDisplayName,
Expand Down Expand Up @@ -1006,31 +1005,34 @@ export default function UserProfile() {
</p>
</div>
</div>
{updateStatus.isUpdateAvailable && (
<UpdatableApp silentlyAutoUpdate={false}>
<ButtonV2 disabled={true}>
<div className="mt-5 md:col-span-2 md:mt-0">
{updateStatus.isChecking ? (
// While checking for updates
<ButtonV2 disabled>
<div className="flex items-center gap-4">
<CareIcon icon="l-exclamation" className="text-2xl" />
{t("update_available")}
<CareIcon icon="l-sync" className="text-2xl animate-spin" />
{t("checking_for_update")}
</div>
</ButtonV2>
</UpdatableApp>
)}
<div className="mt-5 md:col-span-2 md:mt-0">
{!updateStatus.isUpdateAvailable && (
<ButtonV2 disabled={updateStatus.isChecking} onClick={checkUpdates}>
{" "}
) : updateStatus.isUpdateAvailable ? (
// When an update is available
<UpdatableApp silentlyAutoUpdate={false}>
<ButtonV2 disabled>
<div className="flex items-center gap-4">
<CareIcon
icon="l-exclamation"
className="text-2xl text-warning"
/>
{t("update_available")}
</div>
</ButtonV2>
</UpdatableApp>
) : (
// Default state to check for updates
<ButtonV2 onClick={checkUpdates}>
<div className="flex items-center gap-4">
<CareIcon
icon="l-sync"
className={classNames(
"text-2xl",
updateStatus.isChecking && "animate-spin",
)}
/>
{updateStatus.isChecking
? t("checking_for_update")
: t("check_for_update")}
<CareIcon icon="l-sync" className="text-2xl" />
{t("check_for_update")}
</div>
</ButtonV2>
)}
Expand Down

0 comments on commit 116fd93

Please sign in to comment.