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

[Fix] Remove floating promises #11665

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ const CopyApplicationIdAction = ({
fontSize="caption"
data-h2-vertical-align="base(top)"
icon={linkCopied ? CheckIcon : undefined}
onClick={() => {
navigator.clipboard.writeText(id);
onClick={async () => {
await navigator.clipboard.writeText(id);
setLinkCopied(true);
}}
aria-label={
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/ApplicationCard/ApplicationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ const ApplicationCard = ({
classification: application.pool.classification,
});

const deleteApplication = () => {
executeDeleteMutation({
const deleteApplication = async () => {
await executeDeleteMutation({
id: application.id,
}).then((result) => {
if (result.data?.deleteApplication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ describe("AssessmentStepTracker", () => {

it("should have no accessibility errors", async () => {
const { container } = renderAssessmentStepTracker();
await waitFor(() => {
axeTest(container);
await waitFor(async () => {
await axeTest(container);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ const renderComponent = (
describe("EmailVerification", () => {
it("should have no accessibility errors", async () => {
const { container } = renderComponent(getDefaultProps(), getMockClient());
await waitFor(() => {
axeTest(container);
await waitFor(async () => {
await axeTest(container);
});
});

Expand Down
18 changes: 12 additions & 6 deletions apps/web/src/components/EmploymentEquity/EquityOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,19 @@ const EquityOptions = ({
});
};

const handleError = () => {
toast.error(intl.formatMessage(profileMessages.updatingFailed));
};

const handleMultipleFieldSave = (data: UpdateUserAsUserInput) => {
onUpdate(data).then((res) => {
if (res) toast.success(intl.formatMessage(profileMessages.userUpdated));
else {
toast.error(intl.formatMessage(profileMessages.updatingFailed));
}
});
onUpdate(data)
.then((res) => {
if (res) toast.success(intl.formatMessage(profileMessages.userUpdated));
else {
handleError();
}
})
.catch(handleError);
};

return (
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/NotificationList/NotificationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ const NotificationItem = ({

const isTogglingReadStatus = markingAsRead || markingAsUnread;

const toggleReadStatus = () => {
const toggleReadStatus = async () => {
const mutation = isUnread
? executeMarkAsReadMutation
: executeMarkAsUnreadMutation;
mutation({ id: notification.id });
await mutation({ id: notification.id });
};

const createdAt = notification.createdAt
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/components/NotificationList/RemoveDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const RemoveDialog = forwardRef<
DeleteNotification_Mutation,
);

const handleDelete = () => {
executeDeleteMutation({ id }).then((res) => {
const handleDelete = async () => {
await executeDeleteMutation({ id }).then((res) => {
if (res.data?.deleteNotification) {
setIsOpen(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,9 @@ const PoolCandidatesTable = ({
const handleDocDownload = (anonymous: boolean) => {
if (selectedRows.length === 1) {
downloadDoc({ id: selectedRows[0], anonymous })
.then((res) => {
.then(async (res) => {
if (res?.data?.downloadPoolCandidateDoc) {
executeAsyncDownload({
await executeAsyncDownload({
url: apiRoutes.userGeneratedFile(
res.data.downloadPoolCandidateDoc,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ const QualifiedRecruitmentCard = ({
color="black"
fontSize="caption"
icon={linkCopied ? CheckIcon : undefined}
onClick={() => {
navigator.clipboard.writeText(candidate.id);
onClick={async () => {
await navigator.clipboard.writeText(candidate.id);
setLinkCopied(true);
}}
aria-label={intl.formatMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const SkillBrowserDialog = ({

useEffect(() => {
if (watchSkill) {
formTrigger("skill");
void formTrigger("skill");
}
}, [watchSkill, formTrigger]);

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/hooks/useApplicationDownloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ const useApplicationDownloads = () => {

const downloadDoc = ({ id }: { id: Scalars["UUID"]["input"] }) => {
executeDocMutation({ id })
.then((res) => {
.then(async (res) => {
if (res?.data?.downloadApplicationDoc) {
executeAsyncDownload({
await executeAsyncDownload({
url: paths.userGeneratedFile(res.data.downloadApplicationDoc),
fileName: res.data.downloadApplicationDoc,
});
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/hooks/usePoolMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const usePoolMutations = (returnPath?: string) => {
}),
);
} else {
handleUpdateError();
void handleUpdateError();
}
})
.catch(handleUpdateError);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/hooks/useUserDownloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const useUserDownloads = () => {
executeAsyncDownload({
url: paths.userGeneratedFile(res.data.downloadUserDoc),
fileName: res.data.downloadUserDoc,
});
}).catch(handleDownloadError);
} else {
handleDownloadError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ export const GettingStartedForm = ({
],
});

const onSubmit = (values: FormValues) => {
handleSubmit(
const onSubmit = async (values: FormValues) => {
await handleSubmit(
{
firstName: values.firstName,
lastName: values.lastName,
Expand Down Expand Up @@ -402,9 +402,9 @@ const GettingStarted = () => {
id,
email: emptyToNull(generalInput.email),
},
}).then((generalResult) => {
}).then(async (generalResult) => {
if (generalResult.data?.updateUserAsUser) {
executeNotificationMutation({
await executeNotificationMutation({
enabledEmailNotifications: notificationInput,
}).then((notificationResult) => {
if (notificationResult.data?.updateEnabledNotifications) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const AssetSkillsSection = ({
skillSelected: string,
skillLevel: SkillLevel,
) => {
poolSkillMutations.create(pool.id, skillSelected, {
await poolSkillMutations.create(pool.id, skillSelected, {
type: PoolSkillType.Nonessential,
requiredLevel: skillLevel,
});
Expand All @@ -85,13 +85,13 @@ const AssetSkillsSection = ({
poolSkillSelected: string,
skillLevel: SkillLevel,
) => {
poolSkillMutations.update(poolSkillSelected, {
await poolSkillMutations.update(poolSkillSelected, {
requiredLevel: skillLevel,
});
};

const handleRemove = async (poolSkillSelected: string) => {
poolSkillMutations.delete(poolSkillSelected);
await poolSkillMutations.delete(poolSkillSelected);
};

// disabled unless status is draft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const EssentialSkillsSection = ({
skillSelected: string,
skillLevel: SkillLevel,
) => {
poolSkillMutations.create(pool.id, skillSelected, {
await poolSkillMutations.create(pool.id, skillSelected, {
type: PoolSkillType.Essential,
requiredLevel: skillLevel,
});
Expand All @@ -85,13 +85,13 @@ const EssentialSkillsSection = ({
poolSkillSelected: string,
skillLevel: SkillLevel,
) => {
poolSkillMutations.update(poolSkillSelected, {
await poolSkillMutations.update(poolSkillSelected, {
requiredLevel: skillLevel,
});
};

const handleRemove = async (poolSkillSelected: string) => {
poolSkillMutations.delete(poolSkillSelected);
await poolSkillMutations.delete(poolSkillSelected);
};

// disabled unless status is draft
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ const GeneralQuestionsSection = ({
);
const { isSubmitting } = useEditPoolContext();

const handleUpdate = (newQuestions: GeneralQuestion[]) => {
const handleUpdate = async (newQuestions: GeneralQuestion[]) => {
setIsUpdating(true);
const generalQuestions = repeaterQuestionsToSubmitData(
newQuestions,
questions,
);
onSave({ generalQuestions }).then(() => {
await onSave({ generalQuestions }).then(() => {
setIsUpdating(false);
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const ActionCell = (
}}
onSave={async (value) => {
if (value.skill && value.skillLevel) {
onUpdate(poolSkillId, value.skillLevel);
await onUpdate(poolSkillId, value.skillLevel);
}
}}
/>
Expand Down Expand Up @@ -204,7 +204,7 @@ const SkillTable = ({
skills={availableSkills}
onSave={async (value) => {
if (value.skill && value.skillLevel) {
onCreate(value.skill, value.skillLevel);
await onCreate(value.skill, value.skillLevel);
}
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ const UpdatePublishedProcessDialog = ({
});
};

const handleSave = () => {
methods.handleSubmit(handleUpdate)();
const handleSave = async () => {
await methods.handleSubmit(handleUpdate)();
};

const label = intl.formatMessage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ export const PoolPoster = ({
mode="inline"
color="secondary"
icon={linkCopied ? CheckIcon : undefined}
onClick={() => {
navigator.clipboard.writeText(window.location.href);
onClick={async () => {
await navigator.clipboard.writeText(window.location.href);
setLinkCopied(true);
setTimeout(() => {
setLinkCopied(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { Pending, ThrowNotFound } from "@gc-digital-talent/ui";
import { toast } from "@gc-digital-talent/toast";
import { ROLE_NAME } from "@gc-digital-talent/auth";
import { useLogger } from "@gc-digital-talent/logger";

import useRequiredParams from "~/hooks/useRequiredParams";
import AssessmentStepTracker, {
Expand Down Expand Up @@ -77,6 +78,7 @@ const ScreeningAndEvaluationPage = () => {
const { poolId } = useRequiredParams<RouteParams>("poolId");
const client = useClient();
const intl = useIntl();
const logger = useLogger();
const [fetchingCandidates, setFetchingCandidates] = useState<boolean>(true);
const [candidates, setCandidates] = useState<
FragmentType<typeof AssessmentStepTracker_CandidateFragment>[]
Expand Down Expand Up @@ -132,11 +134,11 @@ const ScreeningAndEvaluationPage = () => {
[client, intl, lastPage],
);

const handleFilterSubmit: SubmitHandler<FormValues> = (formData) => {
const handleFilterSubmit: SubmitHandler<FormValues> = async (formData) => {
const transformedData: PoolCandidateSearchInput =
transformFormValuesToFilterState(formData, poolId);

batchLoader(transformedData).then((res) => {
await batchLoader(transformedData).then((res) => {
setCandidates(res);
});
};
Expand All @@ -147,9 +149,13 @@ const ScreeningAndEvaluationPage = () => {
applicantFilter: { pools: [{ id: poolId }] },
suspendedStatus: CandidateSuspendedFilter.Active,
expiryStatus: CandidateExpiryFilter.Active,
}).then((res) => {
setCandidates(res);
});
})
.then((res) => {
setCandidates(res);
})
.catch((err) => {
logger.error(err);
});
}

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const SkillPortfolioTable = ({
context="library"
skills={unclaimedSkills}
onSave={async (value) => {
executeCreateMutation({
await executeCreateMutation({
userId: userAuthInfo?.id ?? "",
skillId: value?.skill ?? "",
userSkill: {
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-config-custom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ module.exports = {
"@typescript-eslint/only-throw-error": "off", // Remove in #11378
"@typescript-eslint/no-misused-promises": "off", // Remove in #11379
"@typescript-eslint/no-base-to-string": "off", // Remove in #11380
"@typescript-eslint/no-floating-promises": "off", // Remove in #11381
"@typescript-eslint/prefer-promise-reject-errors": "off", // Remove in #11382

// Remove in #11384
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const Template: StoryFn<ComboboxType> = (args) => {
.then((newOptions) => {
setFilteredOptions(newOptions);
})
.catch((err) => action("error")(err))
.finally(() => {
setIsSearching(false);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const AsyncTemplate: StoryFn<AsyncArgs> = (args) => {
.then((res: Pool) => {
setPool(res);
})
.catch((err) => action("error")(err))
.finally(() => {
setFetching(false);
});
Expand Down
6 changes: 3 additions & 3 deletions packages/forms/src/components/RichTextInput/LinkDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ const LinkDialog = ({ editor }: LinkDialogProps) => {
const methods = useForm<FormValues>();
const actionProps = methods.register("action");

const handleSave = (action: FormValues["action"]) => {
const handleSave = async (action: FormValues["action"]) => {
methods.setValue("action", action);
methods.handleSubmit(handleSubmit)();
await methods.handleSubmit(handleSubmit)();
};

const handleOpenChange = (newOpen: boolean) => {
Expand All @@ -102,7 +102,7 @@ const LinkDialog = ({ editor }: LinkDialogProps) => {
const handleKeyDown: KeyboardEventHandler = (e) => {
if (e.key === "Enter") {
e.preventDefault();
handleSave("add");
void handleSave("add");
}
};

Expand Down
Loading