Skip to content

Commit

Permalink
Merge pull request #202 from dump-hr/sponsor-tier
Browse files Browse the repository at this point in the history
Sponsor tier limitations
  • Loading branch information
bdeak4 authored Feb 14, 2024
2 parents e72706f + d89fcb7 commit 6c424a8
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 18 deletions.
1 change: 1 addition & 0 deletions apps/api/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const company = pgTable('company', {
name: text('name').notNull(),
username: text('username').unique().notNull(),
description: text('description'),
opportunitiesDescription: text('opportunities_description'),
website: text('website_url'),
boothLocation: text('booth_location'),
logoImage: text('logo_image'),
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/company/company.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export class CompanyController {
@Patch('/description')
async updateDescription(
@Req() { user }: AuthenticatedRequest,
@Body() { description }: CompanyModifyDescriptionDto,
@Body() data: CompanyModifyDescriptionDto,
) {
return await this.companyService.updateDescription(user.id, description);
return await this.companyService.updateDescription(user.id, data);
}

@UseGuards(SponsorGuard)
Expand Down
12 changes: 10 additions & 2 deletions apps/api/src/company/company.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
CompanyDto,
CompanyModifyDescriptionDto,
CompanyModifyDto,
CompanyPublicDto,
} from '@ddays-app/types';
Expand Down Expand Up @@ -43,6 +44,7 @@ export class CompanyService {
category: company.category,
name: company.name,
description: company.description,
opportunitiesDescription: company.opportunitiesDescription,
website: company.website,
boothLocation: company.boothLocation,
logoImage: company.logoImage,
Expand Down Expand Up @@ -77,6 +79,7 @@ export class CompanyService {
category: company.category,
name: company.name,
description: company.description,
opportunitiesDescription: company.opportunitiesDescription,
website: company.website,
boothLocation: company.boothLocation,
logoImage: company.logoImage,
Expand Down Expand Up @@ -156,19 +159,21 @@ export class CompanyService {

async updateDescription(
companyId: number,
description: string,
data: CompanyModifyDescriptionDto,
): Promise<CompanyPublicDto> {
const [updatedCompany] = await db
.update(company)
.set({
description,
description: data.description,
opportunitiesDescription: data.opportunitiesDescription,
})
.where(eq(company.id, companyId))
.returning({
id: company.id,
category: company.category,
name: company.name,
description: company.description,
opportunitiesDescription: company.opportunitiesDescription,
website: company.website,
boothLocation: company.boothLocation,
logoImage: company.logoImage,
Expand Down Expand Up @@ -200,6 +205,7 @@ export class CompanyService {
category: company.category,
name: company.name,
description: company.description,
opportunitiesDescription: company.opportunitiesDescription,
website: company.website,
boothLocation: company.boothLocation,
logoImage: company.logoImage,
Expand Down Expand Up @@ -231,6 +237,7 @@ export class CompanyService {
category: company.category,
name: company.name,
description: company.description,
opportunitiesDescription: company.opportunitiesDescription,
website: company.website,
boothLocation: company.boothLocation,
logoImage: company.logoImage,
Expand Down Expand Up @@ -262,6 +269,7 @@ export class CompanyService {
category: company.category,
name: company.name,
description: company.description,
opportunitiesDescription: company.opportunitiesDescription,
website: company.website,
boothLocation: company.boothLocation,
logoImage: company.logoImage,
Expand Down
3 changes: 3 additions & 0 deletions apps/sponsor/src/constants/forms.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { CompanyCategory } from '@ddays-app/types';

import { Description } from '../formSteps/Description';
import { InterestPicker } from '../formSteps/InterestPicker';
import { Job } from '../formSteps/Job/Job';
Expand All @@ -21,6 +23,7 @@ export const sponsorForm: SponsorForm = {
title: 'Fotografije tvrtke',
description: 'Predaja do x x',
component: PhotoUpload,
tier: [CompanyCategory.Gold],
},
[FormSteps.Videos]: {
title: 'Videozapis tvrtke',
Expand Down
29 changes: 24 additions & 5 deletions apps/sponsor/src/formSteps/Description/Description.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CompanyCategory } from '@ddays-app/types';
import { useState } from 'react';

import { useCompanyGetCurrentPublic } from '../../api/company/useCompanyGetCurrentPublic';
Expand All @@ -8,21 +9,25 @@ import c from './Description.module.scss';

export const Description: FormComponent = ({ close }) => {
const [description, setDescription] = useState<string>();
const [opportunitiesDescription, setOpportunitiesDescription] =
useState<string>();

const { data, error, isLoading } = useCompanyGetCurrentPublic();
const { data: company, error, isLoading } = useCompanyGetCurrentPublic();
const updateDescription = useCompanyUpdateDescription();

if (error) {
return <div>{error.toString()}</div>;
}

if (isLoading || !data) {
if (isLoading || !company) {
return <div>Loading...</div>;
}

const handleSubmit = async () => {
await updateDescription.mutateAsync({
description: description ?? data.description ?? '',
description: description ?? company.description ?? '',
opportunitiesDescription:
opportunitiesDescription ?? company.opportunitiesDescription ?? '',
});
close();
};
Expand All @@ -37,14 +42,28 @@ export const Description: FormComponent = ({ close }) => {
</p>
<div className={c.inputContainer}>
<TextArea
value={description ?? data.description ?? ''}
value={description ?? company.description ?? ''}
onChange={(value) => setDescription(value)}
limit={70}
deviation={5}
label='Opis tvrtke'
rows={16}
rows={8}
/>
</div>
{company.category === CompanyCategory.Gold && (
<div className={c.inputContainer}>
<TextArea
value={
opportunitiesDescription ?? company.opportunitiesDescription ?? ''
}
onChange={(value) => setOpportunitiesDescription(value)}
limit={70}
deviation={5}
label='Poslovne prilike, o poslovima i projektima'
rows={8}
/>
</div>
)}
<button onClick={handleSubmit} className={c.button}>
Spremi
</button>
Expand Down
18 changes: 16 additions & 2 deletions apps/sponsor/src/formSteps/Job/Job.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JobModifyForCompanyDto } from '@ddays-app/types';
import { CompanyCategory, JobModifyForCompanyDto } from '@ddays-app/types';
import clsx from 'clsx';
import { useEffect, useState } from 'react';

Expand All @@ -10,6 +10,19 @@ import { TextArea } from '../../components/TextArea';
import { FormComponent } from '../../types/form';
import c from './Job.module.scss';

const getMaxJobsPerTier = (category: CompanyCategory) => {
switch (category) {
case CompanyCategory.Bronze:
return 1;
case CompanyCategory.Silver:
return 3;
case CompanyCategory.Gold:
return 3;
default:
return 0;
}
};

export const Job: FormComponent = ({ close }) => {
const [jobs, setJobs] = useState<JobModifyForCompanyDto[]>([]);

Expand Down Expand Up @@ -122,7 +135,8 @@ export const Job: FormComponent = ({ close }) => {
</div>

<div>
{jobs.length < 3 && (
{jobs.length <
getMaxJobsPerTier(company?.category as CompanyCategory) && (
<button onClick={handleAdd} className={clsx(c.button, c.secondary)}>
Dodaj oglas
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ h3 {
font-weight: 400;
size: 14px;
color: rgba(255, 255, 255, 0.5);
display: flex;
flex-direction: column;
gap: 24px;
}

.pillGroup {
Expand Down
9 changes: 6 additions & 3 deletions apps/sponsor/src/pages/CompanyProfile/CompanyProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ export const CompanyProfile = () => {
title='Uvod'
buttonText='Dodajte svoje kratko predstavljanje'
onClick={() => setCurrentModal(FormSteps.Description)}>
<p className={c.cardContentParagraph}>
{company?.description || 'Nema opisa'}
</p>
<div className={c.cardContentParagraph}>
<p>{company?.description || 'Nema opisa'}</p>
{company?.opportunitiesDescription && (
<p>{company.opportunitiesDescription}</p>
)}
</div>
</InfoCard>
<InfoCard
title='Interesi'
Expand Down
15 changes: 11 additions & 4 deletions apps/sponsor/src/pages/MaterialsPage/MaterialsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CompanyCategory } from '@ddays-app/types';
import { useState } from 'react';
import { Helmet } from 'react-helmet-async';

Expand Down Expand Up @@ -50,6 +51,8 @@ export const MaterialsPage: React.FC = () => {
//[FormSteps.SwagBag]: false,
};

if (!company) return null;

return (
<>
<Helmet>
Expand All @@ -58,8 +61,13 @@ export const MaterialsPage: React.FC = () => {
<main className={c.page}>
<div className={c.pageWrapper}>
<section className={c.itemsWrapper}>
{Object.entries(sponsorForm).map(
([key, { description, title }], index) => (
{Object.entries(sponsorForm)
.filter(
([, fs]) =>
!fs.tier ||
fs.tier.includes(company.category as CompanyCategory),
)
.map(([key, { description, title }], index) => (
<article
className={c.item}
onClick={() => {
Expand All @@ -84,8 +92,7 @@ export const MaterialsPage: React.FC = () => {
<img src={ArrowRightSvg} alt='Open' />
</div>
</article>
),
)}
))}

{currentForm && (
<Modal
Expand Down
2 changes: 2 additions & 0 deletions apps/sponsor/src/types/form.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CompanyCategory } from '@ddays-app/types';
import React from 'react';

export enum FormSteps {
Expand Down Expand Up @@ -25,6 +26,7 @@ export type FormStep = {
title: string;
description: string;
component: FormComponent;
tier?: CompanyCategory[];
};

export type SponsorForm = {
Expand Down
11 changes: 11 additions & 0 deletions packages/types/src/dto/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type CompanyPublicDto = {
name: string;

description?: string;
opportunitiesDescription?: string;
website?: string;
boothLocation?: string;
logoImage?: string;
Expand All @@ -30,6 +31,7 @@ export type CompanyDto = {
username: string;
password: string;
description?: string;
opportunitiesDescription?: string;
website?: string;
boothLocation?: string;
logoImage?: string;
Expand All @@ -54,6 +56,11 @@ export class CompanyModifyDto {
@IsBetweenWordCount(70, 5)
description: string;

@IsOptional()
@IsString()
@IsBetweenWordCount(70, 5)
opportunitiesDescription: string;

@IsOptional()
@IsString()
website: string;
Expand All @@ -76,4 +83,8 @@ export class CompanyModifyDescriptionDto {
@IsString()
@IsBetweenWordCount(70, 5)
description: string;

@IsString()
@IsBetweenWordCount(70, 5)
opportunitiesDescription: string;
}

0 comments on commit 6c424a8

Please sign in to comment.