Skip to content

Commit

Permalink
Merge branch 'staging' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbeno committed Oct 28, 2024
2 parents 9b999df + 104ce09 commit 7f1e547
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { applicationsApiClient } from "api-client/resources/applications";
import { issuesApiClient } from "api-client/resources/issues";
import { meApiClient } from "api-client/resources/me";
import { useParams } from "next/navigation";
import { useEffect, useState } from "react";
import { useState } from "react";
import { useForm } from "react-hook-form";

import ProjectApi from "src/api/Project";
Expand Down Expand Up @@ -70,12 +70,6 @@ export function useApplyIssueDrawer({ state }: Pick<TApplyIssueDrawer.Props, "st
},
});

useEffect(() => {
form.reset({
githubComment: application?.githubComment ?? "",
});
}, [application]);

async function getPermissionsOnError(err: FetchError) {
if (err.errorType === HttpStatusStrings.FORBIDDEN) {
await getPermissions();
Expand Down Expand Up @@ -135,7 +129,9 @@ export function useApplyIssueDrawerState() {

export function useApplyIssuePrefillLabel() {
const arrayOfLabels = ApplyIssuesPrefillLabels;
const randomIndex = Math.floor(Math.random() * arrayOfLabels.length);

return arrayOfLabels[randomIndex];
return () => {
const randomIndex = Math.floor(Math.random() * arrayOfLabels.length);
return arrayOfLabels[randomIndex];
};
}
21 changes: 7 additions & 14 deletions components/features/apply-issue-drawer/apply-issue-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ export function ApplyIssueDrawer({ state }: TApplyIssueDrawer.Props) {
const [isOpenGrantPermission, setIsOpenGrantPermission] = useState(false);
const { isAuthenticated } = useAuth0();
const { capture } = usePosthog();
const prefillLabel = useApplyIssuePrefillLabel();
const { user } = useCurrentUser();
const router = useRouter();
const [shouldDeleteGithubComment, setShouldDeleteGithubComment] = useState(false);
const {
project: { data: project },
form: { control, reset, setValue, getValues, handleSubmit, watch },
form: { control, reset, getValues, handleSubmit },
issue,
getIssue: { isLoading: issueIsLoading },
application,
Expand All @@ -57,9 +56,9 @@ export function ApplyIssueDrawer({ state }: TApplyIssueDrawer.Props) {
handleCancel,
} = useApplyIssueDrawer({ state });

const isLoading = issueIsLoading || applicationIsLoading;
const prefillLabel = useApplyIssuePrefillLabel();

const githubComment = watch("githubComment");
const isLoading = issueIsLoading || applicationIsLoading;

useEffect(() => {
if (isOpen && project) {
Expand All @@ -78,16 +77,10 @@ export function ApplyIssueDrawer({ state }: TApplyIssueDrawer.Props) {
}, [isOpen]);

useEffect(() => {
if (prefillLabel && !githubComment) {
setValue("githubComment", prefillLabel);
}
}, [prefillLabel, githubComment]);

useEffect(() => {
if (application) {
setValue("githubComment", application?.githubComment ?? "");
}
}, [application]);
reset({
githubComment: application?.githubComment ?? prefillLabel(),
});
}, [application, isOpen]);

const { canApply, handleVerifyPermissions } = usePublicRepoScope({
onSuccessCallback: actionType => {
Expand Down

0 comments on commit 7f1e547

Please sign in to comment.