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

feat: translate web-components from header to inputs #2468

Merged
merged 7 commits into from
Sep 18, 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
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
'lingui/no-unlocalized-strings': [
1,
{
ignoreFunction: ['test', 'makeStyles', 'withStyles'],
ignoreFunction: ['test', 'makeStyles', 'withStyles', 'cn'],
ignoreAttribute: [
'allow',
'sx',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ const Photo = ({
src,
caption,
credit,
locationText,
sx = [],
}: CardMediaProps & { caption?: string; credit?: string }): JSX.Element => {
}: CardMediaProps & {
caption?: string;
credit?: string;
locationText: string;
}): JSX.Element => {
return (
<Card sx={[{ height: [216, 293], position: 'relative' }, ...sxToArray(sx)]}>
<CardMedia
Expand All @@ -19,6 +24,7 @@ const Photo = ({
/>
{(caption || credit) && (
<FileDropBottomBar
locationText={locationText}
caption={caption}
credit={credit}
sx={{ position: 'absolute', bottom: 0 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const itemDisplay = () => (
<ItemDisplay name="Item">Some content</ItemDisplay>
);

export const photo = () => <Photo src={imgSrc} />;
export const photo = () => <Photo src={imgSrc} locationText="Location" />;

export const reviewCard = () => (
<ReviewCard title="review card" onEditClick={onClick} editText="Edit">
<Photo src={imgSrc} />
<Photo src={imgSrc} locationText="Location" />
</ReviewCard>
);
3 changes: 2 additions & 1 deletion web-components/src/components/cards/card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const projectCard = (): JSX.Element => (
estimatedIssuance: '200',
stripePaymentLink: 'https://stripe.com',
}}
draftText="Draft"
/>
</Box>
);
Expand Down Expand Up @@ -359,6 +360,6 @@ export const reviewCard = (): JSX.Element => (
<ItemDisplay name="URL">
<a href="http://www.url.com/">www.url.com</a>
</ItemDisplay>
<Photo src="/coorong.png" />
<Photo src="/coorong.png" locationText="Location" />
</ReviewCard>
);
2 changes: 0 additions & 2 deletions web-components/src/components/credits/CreditsGauge.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react';
import Grid from '@mui/material/Grid';
import { Theme } from '@mui/material/styles';
import { makeStyles } from 'tss-react/mui';

import { pluralize } from '../../utils/pluralize';
import Gauge from './Gauge';
import GaugeText from './GaugeText';

Expand Down
6 changes: 6 additions & 0 deletions web-components/src/components/footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface FooterProps {
newsletterSuccessChildren: React.ReactNode;
newsletterSubmitLabel: string;
newsletterInputPlaceholder: string;
requiredMessage: string;
invalidEmailMessage: string;
}

const useStyles = makeStyles()((theme: Theme) => ({
Expand Down Expand Up @@ -116,6 +118,8 @@ export default function Footer({
termsText,
privacyText,
joinText,
requiredMessage,
invalidEmailMessage,
apiUri = 'http://localhost:5000',
}: FooterProps): JSX.Element {
const { classes } = useStyles();
Expand Down Expand Up @@ -176,6 +180,8 @@ export default function Footer({
apiUri={apiUri}
gridXs={{ textField: 7, button: 5 }}
successChildren={newsletterSuccessChildren}
requiredMessage={requiredMessage}
invalidEmailMessage={invalidEmailMessage}
/>
</Box>
</Grid>
Expand Down
25 changes: 23 additions & 2 deletions web-components/src/components/form/BasketPutForm/BasketPutForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Field, Form, Formik, FormikErrors } from 'formik';
import { Body } from '../../../components/typography';
import AmountField from '../../inputs/AmountField';
import SelectTextField, { Option } from '../../inputs/SelectTextField';
import { requiredMessage, validateAmount } from '../../inputs/validation';
import { validateAmount } from '../../inputs/validation';
import { RegenModalProps } from '../../modal';
import Submit from '../Submit';
import { BasketPutFormOnChange } from './BasketPutForm.OnChange';
Expand All @@ -19,11 +19,17 @@ export interface BasketPutProps {
amountLabel: string;
submitLabel: string;
submitErrorText: string;
requiredMessage: string;
invalidAmount: string;
insufficientCredits: string;
invalidDecimalCount: string;
onSubmit: (values: FormValues) => Promise<void>;
onBatchDenomChange?: (batchDenom: string | undefined) => void;
}

interface FormProps extends BasketPutProps {
maxLabel: string;
availableLabel: string;
onClose: RegenModalProps['onClose'];
}

Expand All @@ -34,6 +40,8 @@ export interface FormValues {
}

const BasketPutForm: React.FC<React.PropsWithChildren<FormProps>> = ({
maxLabel,
availableLabel,
batchDenoms,
basketOptions,
availableTradableAmount,
Expand All @@ -43,6 +51,10 @@ const BasketPutForm: React.FC<React.PropsWithChildren<FormProps>> = ({
basketLabel,
submitLabel,
submitErrorText,
requiredMessage,
invalidAmount,
insufficientCredits,
invalidDecimalCount,
onClose,
onSubmit,
onBatchDenomChange,
Expand Down Expand Up @@ -70,7 +82,14 @@ const BasketPutForm: React.FC<React.PropsWithChildren<FormProps>> = ({
if (!values.basketDenom) {
errors.basketDenom = requiredMessage;
}
const errAmount = validateAmount(availableTradableAmount, values.amount);
const errAmount = validateAmount({
availableTradableAmount,
requiredMessage,
invalidAmount,
insufficientCredits,
invalidDecimalCount,
amount: values.amount,
});
if (errAmount) errors.amount = errAmount;

return errors;
Expand Down Expand Up @@ -103,6 +122,8 @@ const BasketPutForm: React.FC<React.PropsWithChildren<FormProps>> = ({
native={false}
/>
<AmountField
maxLabel={maxLabel}
availableLabel={availableLabel}
name="amount"
label={amountLabel}
availableAmount={availableTradableAmount}
Expand Down
41 changes: 34 additions & 7 deletions web-components/src/components/form/BasketTakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ export interface BasketTakeProps extends BottomCreditRetireFieldsProps {
retirementInfoText: string;
submitLabel: string;
submitErrorText: string;
invalidMemoLength: string;
onSubmit: (values: MsgTakeValues) => void;
}

// Input (args)
interface FormProps extends BasketTakeProps {
requiredMessage: string;
invalidAmount: string;
insufficientCredits: string;
invalidDecimalCount: string;
maxLabel: string;
availableLabel: string;
onClose: RegenModalProps['onClose'];
}

Expand All @@ -85,7 +92,6 @@ const BasketTakeForm: React.FC<React.PropsWithChildren<FormProps>> = ({
basket,
basketDisplayDenom,
balance,
amountErrorText,
amountLabel,
retireOnTakeLabel,
retireOnTakeTooltip,
Expand All @@ -94,6 +100,13 @@ const BasketTakeForm: React.FC<React.PropsWithChildren<FormProps>> = ({
submitErrorText,
retirementInfoText,
bottomTextMapping,
maxLabel,
availableLabel,
requiredMessage,
invalidAmount,
insufficientCredits,
invalidDecimalCount,
invalidMemoLength,
onClose,
onSubmit,
}) => {
Expand All @@ -113,7 +126,14 @@ const BasketTakeForm: React.FC<React.PropsWithChildren<FormProps>> = ({
): FormikErrors<CreditTakeFormValues> => {
let errors: FormikErrors<CreditTakeFormValues> = {};

const errAmount = validateAmount(balance, values.amount, amountErrorText);
const errAmount = validateAmount({
availableTradableAmount: balance,
requiredMessage,
invalidAmount,
insufficientCredits,
invalidDecimalCount,
amount: values.amount,
});
if (errAmount) errors.amount = errAmount;

// Retire form validation (optional subform)
Expand All @@ -125,12 +145,17 @@ const BasketTakeForm: React.FC<React.PropsWithChildren<FormProps>> = ({
stateProvince: values.stateProvince,
postalCode: values.postalCode,
};
errors = validateCreditRetire(
balance,
retirementValues,
errors = validateCreditRetire({
availableTradableAmount: balance,
values: retirementValues,
errors,
stateProvinceErrorText,
);
stateProvinceError: stateProvinceErrorText,
requiredMessage,
invalidAmount,
insufficientCredits,
invalidDecimalCount,
invalidMemoLength,
});
}
return errors;
};
Expand Down Expand Up @@ -158,6 +183,8 @@ const BasketTakeForm: React.FC<React.PropsWithChildren<FormProps>> = ({
<Form>
<>
<AmountField
maxLabel={maxLabel}
availableLabel={availableLabel}
name="amount"
label={amountLabel}
availableAmount={balance}
Expand Down
Loading