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

view shelter 2 (DEV-1079) #781

Merged
merged 5 commits into from
Dec 17, 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
3 changes: 3 additions & 0 deletions apps/shelter-web/src/assets/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
--color-neutral-70: #a8aeb8;
--color-neutral-90: #d3d9e3;
--color-neutral-98: #e8ecf2;
--color-neutral-99: #f4f6fd;
--color-success-30: #007934;
--color-success-90: #ddf8e8;
}

* {
Expand Down
3 changes: 3 additions & 0 deletions apps/shelter-web/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = {
'neutral-70': 'var(--color-neutral-70)',
'neutral-90': 'var(--color-neutral-90)',
'neutral-98': 'var(--color-neutral-98)',
'neutral-99': 'var(--color-neutral-99)',
'success-30': 'var(--color-success-30)',
'success-90': 'var(--color-success-90)',
},
},
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions libs/react/components/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["plugin:@nx/react", "../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions libs/react/components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# react-components

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test react-components` to execute the unit tests via [Jest](https://jestjs.io).
11 changes: 11 additions & 0 deletions libs/react/components/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable */
export default {
displayName: 'react-components',
preset: '../../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../../coverage/libs/react/components',
};
16 changes: 16 additions & 0 deletions libs/react/components/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "react-components",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/react/components/src",
"projectType": "library",
"tags": [],
"targets": {
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/react/components/jest.config.ts"
}
}
}
}
1 change: 1 addition & 0 deletions libs/react/components/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib';
42 changes: 42 additions & 0 deletions libs/react/components/src/lib/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import clsx from 'clsx';
import { ButtonHTMLAttributes } from 'react';

interface IButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
/**
* The size of the button. Determines padding and font size.
* - `sm`: 26px.
* - `md`: Medium size (default).
* - `lg`: Large size.
*/
size?: 'sm' | 'md' | 'lg';
/**
* The variant of the button. Determines background and text color.
* - `primary`: primary-20 background, white text.
* - `secondary`: neutral-99 background, primary-20 text.
*/
variant?: 'primary' | 'secondary';
}

export function Button(props: IButtonProps) {
const { size = 'md', variant = 'primary', className, ...rest } = props;

const sizeClasses = {
sm: 'h-[26px] px-2 text-sm',
md: 'h-[32px] px-4 text-base',
lg: 'h-[40px] px-6 text-lg',
};

const variantClasses = {
primary: 'bg-primary-20 text-white',
secondary: 'bg-neutral-99 text-primary-20',
};

const buttonClass = clsx(
className,
'font-semibold text-sm focus:outline-none rounded-lg',
sizeClasses[size],
variantClasses[variant]
);

return <button className={buttonClass} {...rest} />;
}
1 change: 1 addition & 0 deletions libs/react/components/src/lib/Button/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Button as default } from './Button';
25 changes: 25 additions & 0 deletions libs/react/components/src/lib/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import clsx from 'clsx';
import { ReactNode } from 'react';

interface ICardProps {
children: ReactNode;
px?: 'px-0' | 'px-6';
pb?: 'pb-0' | 'pb-6';
title?: string;
className?: string;
}

export function Card(props: ICardProps) {
const { children, px = 'px-6', title, pb = 'pb-6', className } = props;

const baseClasses = 'border-neutral-90 border pt-6 rounded-lg bg-white';

const pxClasses = clsx(baseClasses, px, pb, className);

return (
<div className={pxClasses}>
{title && <h3 className="font-semibold mb-2">{title}</h3>}
<div className="text-sm">{children}</div>
</div>
);
}
1 change: 1 addition & 0 deletions libs/react/components/src/lib/Card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Card as default } from './Card';
26 changes: 26 additions & 0 deletions libs/react/components/src/lib/Pill/Pill.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import clsx from 'clsx';

interface IPillProps {
/**
* The type of pill. Determines background and border styles.
* - `primary`: Primary-themed pill.
* - `success`: Success-themed pill (default).
*/
type?: 'success';
label: string;
className?: string;
}

export function Pill(props: IPillProps) {
const { label, type = 'success', className } = props;

const baseClasses = 'rounded-[20px] inline-flex items-center justify-center';

const typeClasses = {
success: 'bg-success-90 text-primary-20 px-4 py-1',
Copy link
Contributor

Choose a reason for hiding this comment

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

the color success-90 is only defined in the context of shelter-web. that's ok for today, but we may need add global tailwind config file in libs somwhere. for now maybe just leave a TODO comment?

also, should px-4 py-1 go with baseClasses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

paddings no because if border comes the size will be different

Copy link
Contributor

Choose a reason for hiding this comment

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

aaah ok.

if a different variant can have a border, then another way is to include border in baseClasses (with same color as background), and then just override the border-color. but not necessary

};

const pillClass = clsx(baseClasses, typeClasses[type], className);
Copy link
Contributor

Choose a reason for hiding this comment

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

just FYI: twMerge together with clsx (like in mergeCss) can be really useful here

to allow className to override everyting:
const pillClass = mergeCss(baseClasses, typeClasses[type], className);

to allow adding className, but never overriding baseClasses or typeClasses[type]:
const pillClass = mergeCss(className, baseClasses, typeClasses[type]);


return <div className={pillClass}>{label}</div>;
}
1 change: 1 addition & 0 deletions libs/react/components/src/lib/Pill/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Pill as default } from './Pill';
40 changes: 40 additions & 0 deletions libs/react/components/src/lib/PillContainer/PillContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useState } from 'react';
import Pill from '../Pill';

interface IPillContainerProps {
data: string[];
type?: 'success';
maxVisible: number;
}

export function PillContainer({
data,
type = 'success',
maxVisible,
}: IPillContainerProps) {
const [showAll, setShowAll] = useState(false);
const servicesToDisplay = showAll ? data : data.slice(0, maxVisible);

return (
<div className="flex flex-col">
<div className="flex flex-wrap gap-1">
{servicesToDisplay.map((item, idx) => (
<Pill type={type} label={item} key={idx} />
))}
</div>

{data.length > maxVisible && (
<button
className="mt-3 ml-auto mr-auto"
onClick={() => setShowAll(!showAll)}
aria-label={showAll ? 'Show fewer items' : 'Show all items'}
>
<p className="text-xs font-semibold">
{showAll ? `View Less` : `View All (+${data.length - maxVisible})`}
</p>
{/* <ChevronLeftIcon className={clsx('chevron-icon', { rotated: showAll })} /> */}
</button>
)}
</div>
);
}
1 change: 1 addition & 0 deletions libs/react/components/src/lib/PillContainer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PillContainer as default } from './PillContainer';
4 changes: 4 additions & 0 deletions libs/react/components/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { default as Button } from './Button';
export { default as Card } from './Card';
export { default as Pill } from './Pill';
export { default as PillContainer } from './PillContainer';
24 changes: 24 additions & 0 deletions libs/react/components/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"jsx": "react-jsx",
"esModuleInterop": true,
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions libs/react/components/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
14 changes: 14 additions & 0 deletions libs/react/components/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions libs/react/shelter/src/lib/pages/shelter/Actions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default function Actions() {
return (
<div className="flex items-center py-4 justify-between text-xs px-11 border-neutral-90 border-t border-b mt-4 -mx-4">
<div>
<span>Call</span>
</div>
<div>
<span>Directions</span>
</div>
<div>
<span>Share</span>
</div>
</div>
);
}
48 changes: 48 additions & 0 deletions libs/react/shelter/src/lib/pages/shelter/EntryRequirements.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Card } from '@monorepo/react/components';
import { enumDisplayEntryRequirementChoices } from '../../static';
import { ViewShelterQuery } from './__generated__/shelter.generated';

export default function EntryRequirements({
shelter,
}: {
shelter: ViewShelterQuery['shelter'];
}) {
return (
tglaz marked this conversation as resolved.
Show resolved Hide resolved
<Card title="Entry Requirements">
<div className="flex flex-col gap-2">
{shelter.entryRequirements.map((requirement, idx) => {
if (!requirement.name) return null;
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!requirement.name) return null;
if (!requirement.name) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

return (
<div key={idx}>
{enumDisplayEntryRequirementChoices[requirement.name]}
</div>
);
})}
{shelter.entryInfo && (
<div
className="flex gap-1"
dangerouslySetInnerHTML={{
Copy link

Choose a reason for hiding this comment

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

🚨 issue (security): Avoid using dangerouslySetInnerHTML with string concatenation as it poses security risks

Consider using regular JSX with template literals instead, like:

Entry Info: {shelter?.entryInfo}

__html: 'Entry Info: ' + shelter?.entryInfo,
}}
/>
)}
{shelter.bedFees && (
<div
className="flex gap-1"
dangerouslySetInnerHTML={{
__html: 'Bed Fees: ' + shelter?.bedFees,
}}
/>
)}
{shelter.programFees && (
<div
className="flex gap-1"
dangerouslySetInnerHTML={{
__html: 'Program Fees: ' + shelter?.programFees,
}}
/>
)}
</div>
</Card>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { PillContainer } from '@monorepo/react/components';
import { enumDisplayGeneralServiceChoices } from '../../../static';
import { ViewShelterQuery } from '../__generated__/shelter.generated';

export default function GeneralServices({
shelter,
}: {
shelter: ViewShelterQuery['shelter'];
}) {
return (
<>
<div>
<p>Available General Services</p>
</div>
<div className="pb-6">
<PillContainer
maxVisible={5}
data={
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider simplifying the data transformation using filter and map instead of reduce for improved readability.

The data transformation can be simplified while maintaining all safety checks. Using filter() and map() makes the intent clearer than reduce() here since we're transforming data rather than accumulating it.

data={
  shelter?.generalServices
    ?.filter(service => service.name && enumDisplayGeneralServiceChoices[service.name])
    .map(service => enumDisplayGeneralServiceChoices[service.name]) ?? []
}

This maintains all null checks while being more direct about the data flow: first filter out invalid services, then transform the remaining ones.

shelter.generalServices?.reduce<string[]>((acc, service) => {
if (service.name) {
const displayName =
enumDisplayGeneralServiceChoices[service.name];
if (displayName) acc.push(displayName);
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (displayName) acc.push(displayName);
if (displayName) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

}
return acc;
}, []) || []
}
/>
</div>
</>
);
}
Loading
Loading