Skip to content

Commit

Permalink
renamed files/function to undo-upvote and moved button on the front end
Browse files Browse the repository at this point in the history
  • Loading branch information
jessherlitz committed Jul 26, 2024
1 parent c732cf8 commit c69a0fa
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { type ActionFunctionArgs, json } from '@remix-run/node';

import { downvoteCompanyReview } from '@oyster/core/employment.server';
import { undoUpvoteCompanyReview } from '@oyster/core/employment.server';

import { ensureUserAuthenticated, user } from '@/shared/session.server';

export async function action({ params, request }: ActionFunctionArgs) {
const session = await ensureUserAuthenticated(request);

await downvoteCompanyReview(params.id as string, {
await undoUpvoteCompanyReview(params.id as string, {
memberId: user(session),
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { type ActionFunctionArgs, json } from '@remix-run/node';

import { upvoteCompanyReview } from '@oyster/core/employment.server';
import { track } from '@oyster/infrastructure/mixpanel';

import { ensureUserAuthenticated, user } from '@/shared/session.server';

Expand All @@ -12,12 +11,5 @@ export async function action({ params, request }: ActionFunctionArgs) {
memberId: user(session),
});

track({
event: 'Review Upvoted',
properties: undefined,
request,
user: user(session),
});

return json({});
}
11 changes: 3 additions & 8 deletions apps/member-profile/app/shared/components/company-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { Route } from '@/shared/constants';

type CompanyReviewProps = {
id?: string;
date: string;
company?: {
id: string;
image: string;
Expand Down Expand Up @@ -91,11 +90,6 @@ export const CompanyReview = ({
<Text color="gray-500" variant="sm">
{reviewedAt}
</Text>
<UpvoteCompanyReviewButton
id={id}
upvoted={upvoted}
upvotes={upvotes}
/>

{editable && workExperienceId && (
<div className="ml-auto">
Expand Down Expand Up @@ -169,6 +163,7 @@ export const CompanyReview = ({
</div>

<CompanyReviewText text={text} />
<UpvoteCompanyReviewButton id={id} upvoted={upvoted} upvotes={upvotes} />
</Card>
);
};
Expand Down Expand Up @@ -284,11 +279,11 @@ function UpvoteCompanyReviewButton({
const fetcher = useFetcher();

const action = upvoted
? `/api/company-review/${id}/downvote`
? `/api/company-review/${id}/undo-upvote`
: `/api/company-review/${id}/upvote`;

return (
<fetcher.Form action={action} method="post" className="ml-auto">
<fetcher.Form action={action} method="post" className="mr-auto">
<button
className={cx(
getTextCn({ color: 'gray-500', variant: 'sm' }),
Expand Down
7 changes: 0 additions & 7 deletions packages/core/src/modules/employment/company.types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { z } from 'zod';

export const DownvoteCompanyReviewInput = z.object({
memberId: z.string().min(1),
});

export const UpvoteCompanyReviewInput = z.object({
memberId: z.string().min(1),
});

export type DownvoteCompanyReviewInput = z.infer<
typeof DownvoteCompanyReviewInput
>;
export type UpvoteCompanyReviewInput = z.infer<typeof UpvoteCompanyReviewInput>;
2 changes: 1 addition & 1 deletion packages/core/src/modules/employment/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export { listCompanyEmployees } from './queries/list-company-employees';
export { listCompanyReviews } from './queries/list-company-reviews';
export { addCompanyReview } from './use-cases/add-company-review';
export { editCompanyReview } from './use-cases/edit-company-review';
export { downvoteCompanyReview } from './use-cases/downvote-company-review';
export { undoUpvoteCompanyReview } from './use-cases/undo-upvote-company-review';
export { upvoteCompanyReview } from './use-cases/upvote-company-review';
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { db } from '@oyster/db';

import { type DownvoteCompanyReviewInput } from '@/modules/employment/company.types';
import { type UpvoteCompanyReviewInput } from '@/modules/employment/company.types';

export async function downvoteCompanyReview(
export async function undoUpvoteCompanyReview(
id: string,
input: DownvoteCompanyReviewInput
input: UpvoteCompanyReviewInput
) {
const result = await db.transaction().execute(async (trx) => {
await trx
Expand Down

0 comments on commit c69a0fa

Please sign in to comment.