Skip to content

Commit

Permalink
add empty profile picture + support feed
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiAbdou committed Aug 29, 2024
1 parent 06cf76b commit 6058cf8
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export async function action({ request }: ActionFunctionArgs) {
}

await addCompanyReview({
anonymous: data.anonymous,
rating: data.rating,
recommend: data.recommend,
studentId: data.studentId,
text: data.text,
workExperienceId: data.workExperienceId,
anonymous: data.anonymous,
});

toast(session, {
Expand Down
4 changes: 2 additions & 2 deletions apps/member-profile/app/routes/_profile.companies_.$id.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
listCompanyReviews({
memberId: user(session),
select: [
'companyReviews.anonymous',
'companyReviews.createdAt',
'companyReviews.id',
'companyReviews.rating',
'companyReviews.anonymous',
'companyReviews.recommend',
'companyReviews.text',
'students.id as reviewerId',
Expand Down Expand Up @@ -246,6 +246,7 @@ function ReviewsList() {
return (
<CompanyReview
key={review.id}
anonymous={review.anonymous}
company={{
id: review.companyId || '',
image: review.companyImage || '',
Expand All @@ -270,7 +271,6 @@ function ReviewsList() {
title={review.title || ''}
upvotesCount={review.upvotes}
workExperienceId={review.workExperienceId || ''}
anonymous={review.anonymous}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export async function action({ params, request }: ActionFunctionArgs) {
}

await addCompanyReview({
anonymous: data.anonymous,
rating: data.rating,
recommend: data.recommend,
studentId: data.studentId,
text: data.text,
workExperienceId: data.workExperienceId,
anonymous: data.anonymous,
});

toast(session, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export async function action({ params, request }: ActionFunctionArgs) {
}

await editCompanyReview({
anonymous: data.anonymous,
rating: data.rating,
recommend: data.recommend,
text: data.text,
workExperienceId: data.workExperienceId,
anonymous: data.anonymous,
});

toast(session, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
includeCompanies: true,
memberId: user(session),
select: [
'companyReviews.anonymous',
'companyReviews.createdAt',
'companyReviews.id',
'companyReviews.rating',
'companyReviews.anonymous',
'companyReviews.recommend',
'companyReviews.text',
'students.id as reviewerId',
Expand Down
62 changes: 35 additions & 27 deletions apps/member-profile/app/shared/components/company-review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Card } from '@/shared/components/card';
import { Route } from '@/shared/constants';

type CompanyReviewProps = {
anonymous: boolean;
company?: {
id: string;
image: string;
Expand All @@ -51,7 +52,6 @@ type CompanyReviewProps = {
title: string;
upvotesCount: string | null;
workExperienceId?: string;
anonymous: boolean;
};

export const CompanyReview = ({
Expand Down Expand Up @@ -80,18 +80,14 @@ export const CompanyReview = ({
return (
<Card>
<header className="flex items-center gap-1">
{anonymous ? (
<Text color="gray-500" variant="sm">
Anonymous
</Text>
) : (
<CompanyReviewer
reviewerFirstName={reviewerFirstName}
reviewerLastName={reviewerLastName}
reviewerId={reviewerId}
reviewerProfilePicture={reviewerProfilePicture}
/>
)}
<CompanyReviewer
anonymous={anonymous}
reviewerFirstName={reviewerFirstName}
reviewerLastName={reviewerLastName}
reviewerId={reviewerId}
reviewerProfilePicture={reviewerProfilePicture}
/>

<Text color="gray-500" variant="sm">
&bull;
</Text>
Expand Down Expand Up @@ -181,34 +177,46 @@ export const CompanyReview = ({
};

function CompanyReviewer({
anonymous,
reviewerFirstName,
reviewerId,
reviewerLastName,
reviewerProfilePicture,
}: Pick<
CompanyReviewProps,
| 'anonymous'
| 'reviewerFirstName'
| 'reviewerLastName'
| 'reviewerId'
| 'reviewerProfilePicture'
>) {
return (
<div className="flex w-fit items-center gap-2">
<ProfilePicture
initials={reviewerFirstName![0] + reviewerLastName![0]}
size="32"
src={reviewerProfilePicture || undefined}
/>
{anonymous ? (
<ProfilePicture initials="" size="32" />
) : (
<ProfilePicture
initials={reviewerFirstName[0] + reviewerLastName[0]}
size="32"
src={reviewerProfilePicture || undefined}
/>
)}

<Link
className={cx(
getTextCn({ color: 'gray-500', variant: 'sm' }),
'hover:underline'
)}
to={generatePath(Route['/directory/:id'], { id: reviewerId })}
>
{reviewerFirstName} {reviewerLastName}
</Link>
{anonymous ? (
<Text color="gray-500" variant="sm">
Anonymous
</Text>
) : (
<Link
className={cx(
getTextCn({ color: 'gray-500', variant: 'sm' }),
'hover:underline'
)}
to={generatePath(Route['/directory/:id'], { id: reviewerId })}
>
{reviewerFirstName} {reviewerLastName}
</Link>
)}
</div>
);
}
Expand Down
61 changes: 24 additions & 37 deletions apps/member-profile/app/shared/components/review-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@oyster/core/employment';
import {
Button,
Checkbox,
cx,
Divider,
type FieldProps,
Expand Down Expand Up @@ -38,7 +39,7 @@ export function AddReviewForm({
showExperienceField,
}: AddReviewFormProps) {
return (
<RemixForm className="form" method="post">
<RemixForm className="form" data-gap="2rem" method="post">
{showExperienceField && (
<ExperienceField
error={errors.workExperienceId}
Expand All @@ -47,13 +48,10 @@ export function AddReviewForm({
)}

<TextField error={errors.text} name={keys.text} />

<Divider />

<RatingField error={errors.rating} name={keys.rating} />
<RecommendField error={errors.recommend} name={keys.recommend} />
<AnonymousField error={errors.anonymous} name={keys.anonymous} />

<Form.ErrorMessage>{error}</Form.ErrorMessage>

<Button.Group>
Expand All @@ -66,13 +64,13 @@ export function AddReviewForm({
type EditReviewFormProps = Omit<AddReviewFormProps, 'showExperienceField'> & {
review: Pick<
EditCompanyReviewInput,
'rating' | 'recommend' | 'text' | 'anonymous'
'anonymous' | 'rating' | 'recommend' | 'text'
>;
};

export function EditReviewForm({ error, errors, review }: EditReviewFormProps) {
return (
<RemixForm className="form" method="post">
<RemixForm className="form" data-gap="2rem" method="post">
<TextField
defaultValue={review.text}
error={errors.text}
Expand Down Expand Up @@ -108,6 +106,26 @@ export function EditReviewForm({ error, errors, review }: EditReviewFormProps) {

// Fields

function AnonymousField({ defaultValue, error, name }: FieldProps<boolean>) {
return (
<Form.Field
description="Your name will not be visible to the public."
error={error}
label="Would you like to post this review anonymously?"
labelFor={name}
>
<Checkbox
color="amber-100"
defaultChecked={defaultValue}
label="Post this review anonymously."
id={name}
name={name}
value="1"
/>
</Form.Field>
);
}

function ExperienceField({ defaultValue, error, name }: FieldProps<string>) {
const fetcher = useFetcher<GetWorkExperiencesResult>();

Expand Down Expand Up @@ -234,37 +252,6 @@ function RecommendField({ defaultValue, error, name }: FieldProps<boolean>) {
);
}

function AnonymousField({ error, name, defaultValue }: FieldProps<boolean>) {
return (
<Form.Field
error={error}
label="Would you like to post this review anonymously?"
labelFor={name}
>
<Radio.Group>
<Radio
color="lime-100"
defaultChecked={defaultValue === true}
id={name + '1'}
label="Yes"
name={name}
required
value="1"
/>
<Radio
color="red-100"
defaultChecked={defaultValue === false}
id={name + '0'}
label="No"
name={name}
required
value="0"
/>
</Radio.Group>
</Form.Field>
);
}

function TextField({ defaultValue, error, name }: FieldProps<string>) {
return (
<Form.Field
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/employment/employment.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export const Company = Entity.merge(BaseCompany);
export type Company = z.infer<typeof Company>;

const CompanyReview = z.object({
anonymous: BooleanInput,
rating: z.coerce.number().int().min(0).max(10),
recommend: BooleanInput,
studentId: Student.shape.id,
text: z.string().trim().min(750),
workExperienceId: z.string().trim().min(1),
anonymous: BooleanInput,
});

export const JobOffer = Entity.omit({ deletedAt: true }).extend({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export async function getCompanyReview({ where }: GetCompanyReviewOptions) {
const review = await db
.selectFrom('companyReviews')
.select([
'companyReviews.anonymous',
'companyReviews.id',
'companyReviews.rating',
'companyReviews.recommend',
'companyReviews.text',
'companyReviews.anonymous',
])
.where('companyReviews.workExperienceId', '=', where.workExperienceId)
.executeTakeFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ import { job } from '@/infrastructure/bull/use-cases/job';
import { type AddCompanyReviewInput } from '../employment.types';

export async function addCompanyReview({
anonymous,
rating,
recommend,
studentId,
text,
workExperienceId,
anonymous,
}: AddCompanyReviewInput) {
const review = await db.transaction().execute(async (trx) => {
return trx
.insertInto('companyReviews')
.values({
anonymous,
id: id(),
rating,
recommend,
studentId,
text,
workExperienceId,
anonymous,
})
.returning(['id'])
.executeTakeFirstOrThrow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import { db } from '@oyster/db';
import { type EditCompanyReviewInput } from '../employment.types';

export async function editCompanyReview({
anonymous,
rating,
recommend,
text,
workExperienceId,
anonymous,
}: EditCompanyReviewInput) {
const review = await db.transaction().execute(async (trx) => {
return trx
.updateTable('companyReviews')
.set({
anonymous,
rating,
recommend,
text,
anonymous,
})
.returning(['id'])
.where('workExperienceId', '=', workExperienceId)
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/modules/feed/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ async function getCompanyReviewsMessage(): Promise<string | null> {
.leftJoin('companies', 'companies.id', 'workExperiences.companyId')
.select([
'companies.name as companyName',
'companyReviews.anonymous',
'companyReviews.id',
'companyReviews.rating',
'students.slackId as posterSlackId',
Expand All @@ -101,10 +102,12 @@ async function getCompanyReviewsMessage(): Promise<string | null> {
}

const items = companyReviews
.map(({ companyId, companyName, posterSlackId, rating }) => {
.map(({ anonymous, companyId, companyName, posterSlackId, rating }) => {
const url = new URL('/companies/' + companyId, ENV.STUDENT_PROFILE_URL);

return `• <${url}|*${companyName}*> (${rating}/10) by <@${posterSlackId}>`;
return anonymous
? `• <${url}|*${companyName}*> (${rating}/10) by Anonymous (🫣)`
: `• <${url}|*${companyName}*> (${rating}/10) by <@${posterSlackId}>`;
})
.join('\n');

Expand Down
Loading

0 comments on commit 6058cf8

Please sign in to comment.