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: do not use array index for key / use void for onSubmit #409

Merged
merged 2 commits into from
Nov 28, 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
26 changes: 16 additions & 10 deletions apps/nextjs/src/app/admin/aila/[chatId]/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { OakAccordion, OakPrimaryButton } from "@oaknational/oak-components";

import { trpc } from "@/utils/trpc";

function ModerationListItem({ moderation }: { readonly moderation: Moderation }) {
function ModerationListItem({
moderation,
}: {
readonly moderation: Moderation;
}) {
const { id, invalidatedAt } = moderation;
const [invalidated, setInvalidated] = useState(Boolean(invalidatedAt));
const invalidateModeration = trpc.admin.invalidateModeration.useMutation({
Expand All @@ -28,7 +32,7 @@ function ModerationListItem({ moderation }: { readonly moderation: Moderation })
iconName="cross"
className="ml-auto"
onClick={() =>
invalidateModeration.mutateAsync({ moderationId: id })
void invalidateModeration.mutateAsync({ moderationId: id })
}
isLoading={invalidateModeration.isLoading}
disabled={!!invalidated}
Expand All @@ -41,14 +45,16 @@ function ModerationListItem({ moderation }: { readonly moderation: Moderation })
{moderation.justification}
</blockquote>
<div className="mt-2 space-x-2">
{moderation.categories.map((category, index) => (
<span
key={index}
className="inline-block rounded-md bg-zinc-300 px-8 py-4 text-xs font-semibold text-zinc-800"
>
{String(category)}
</span>
))}
{Array.from(new Set(moderation.categories))
.map((c) => String(c))
.map((category) => (
<span
key={category}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always unique?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we have a set of categories that the moderation can flag

className="inline-block rounded-md bg-zinc-300 px-8 py-4 text-xs font-semibold text-zinc-800"
>
{category}
</span>
))}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export const ModerationFeedbackForm = ({
</span>
</Dialog.Description>
</div>
<form onSubmit={onSubmit}>
<form
onSubmit={(e) => {
e.preventDefault();
void onSubmit();
}}
>
<Textarea
className="min-h-30 w-full resize-none rounded border border-gray-600 bg-transparent px-10 py-[0.6rem] text-base placeholder-gray-700 focus-within:outline-none"
onChange={(e) => setComment(e.target.value)}
Expand All @@ -71,7 +76,13 @@ export const ModerationFeedbackForm = ({
<ChatButton variant="text-link" onClick={closeModal}>
Back to lesson
</ChatButton>
<ChatButton variant="primary" onClick={onSubmit} disabled={!isValid}>
<ChatButton
variant="primary"
onClick={() => {
void onSubmit();
}}
disabled={!isValid}
>
Submit feedback
</ChatButton>
</div>
Expand Down
Loading