[offers][refactor] Refactor text display

pull/499/head
Ai Ling 3 years ago
parent 1ca8fabd52
commit e67f14fc73

@ -9,6 +9,7 @@ import { getLabelForJobTitleType } from '~/components/shared/JobTitles';
import { HorizontalDivider } from '~/../../../packages/ui/dist'; import { HorizontalDivider } from '~/../../../packages/ui/dist';
import { convertMoneyToString } from '~/utils/offers/currency'; import { convertMoneyToString } from '~/utils/offers/currency';
import { getCompanyDisplayText } from '~/utils/offers/string';
import { formatDate } from '~/utils/offers/time'; import { formatDate } from '~/utils/offers/time';
import { JobTypeLabel } from '../constants'; import { JobTypeLabel } from '../constants';
@ -69,7 +70,7 @@ export default function OfferProfileCard({
{getLabelForJobTitleType(title as JobTitleType)}{' '} {getLabelForJobTitleType(title as JobTitleType)}{' '}
{`(${JobTypeLabel[jobType]})`} {`(${JobTypeLabel[jobType]})`}
</p> </p>
<p>{`Company: ${company.name}, ${location}`}</p> <p>{`Company: ${getCompanyDisplayText(company.name, location)}`}</p>
{level && <p>Level: {level}</p>} {level && <p>Level: {level}</p>}
</div> </div>
<div className="col-span-1 row-span-3"> <div className="col-span-1 row-span-3">

@ -93,7 +93,6 @@ export default function OffersProfileSave({
<div className="mt-4 flex gap-4"> <div className="mt-4 flex gap-4">
<div className="grow"> <div className="grow">
<TextInput <TextInput
disabled={true}
isLabelHidden={true} isLabelHidden={true}
label="Edit link" label="Edit link"
value={getProfileLink(profileId, token)} value={getProfileLink(profileId, token)}

@ -289,7 +289,6 @@ export default function OffersSubmissionForm({
className="space-y-6 text-sm" className="space-y-6 text-sm"
onSubmit={handleSubmit(onSubmit)}> onSubmit={handleSubmit(onSubmit)}>
{steps[step]} {steps[step]}
<pre>{JSON.stringify(formMethods.watch(), null, 2)}</pre>
{step === 0 && ( {step === 0 && (
<div className="flex justify-end"> <div className="flex justify-end">
<Button <Button

@ -8,9 +8,10 @@ import { HorizontalDivider } from '@tih/ui';
import type { OfferDisplayData } from '~/components/offers/types'; import type { OfferDisplayData } from '~/components/offers/types';
import { joinWithComma } from '~/utils/offers/string'; import {
getCompanyDisplayText,
import { JobTypeLabel } from '../constants'; getJobDisplayText,
} from '~/utils/offers/string';
type Props = Readonly<{ type Props = Readonly<{
offer: OfferDisplayData; offer: OfferDisplayData;
@ -44,15 +45,12 @@ export default function OfferCard({
<BuildingOffice2Icon className="mr-3 h-5" /> <BuildingOffice2Icon className="mr-3 h-5" />
</span> </span>
<span className="font-bold"> <span className="font-bold">
{joinWithComma(companyName, location?.cityName)} {getCompanyDisplayText(companyName, location)}
</span> </span>
</div> </div>
)} )}
<div className="ml-8 flex flex-row"> <div className="ml-8 flex flex-row">
<p> <p>{getJobDisplayText(jobTitle, jobLevel, jobType)}</p>
{joinWithComma(jobTitle, jobLevel)}{' '}
{jobType && `(${JobTypeLabel[jobType]})`}
</p>
</div> </div>
</div> </div>
{!duration && receivedMonth && ( {!duration && receivedMonth && (

@ -1,3 +1,37 @@
export function joinWithComma(...strings: Array<string | null | undefined>) { import type { JobType } from '@prisma/client';
import { JobTypeLabel } from '~/components/offers/constants';
import type { Location } from '~/types/offers';
function joinWithComma(...strings: Array<string | null | undefined>) {
return strings.filter((value) => !!value).join(', '); return strings.filter((value) => !!value).join(', ');
} }
function getLocationDisplayText({ cityName, countryName }: Location) {
return cityName === countryName
? cityName
: joinWithComma(cityName, countryName);
}
export function getCompanyDisplayText(
companyName?: string | null,
location?: Location | null,
) {
if (!location) {
return companyName;
}
return joinWithComma(companyName, getLocationDisplayText(location));
}
export function getJobDisplayText(
jobTitle?: string | null,
jobLevel?: string | null,
jobType?: JobType | null,
) {
let jobDisplay = joinWithComma(jobTitle, jobLevel);
if (jobType) {
jobDisplay = jobDisplay.concat(` (${JobTypeLabel[jobType]})`);
}
return jobDisplay;
}

Loading…
Cancel
Save