refactor(client): align campers type with stored User (#49982

* refactor(client): align campers type with stored User

* update snapshot
This commit is contained in:
Muhammed Mustafa
2023-04-17 20:16:28 +02:00
committed by GitHub
parent 8300ccb7f0
commit 44a1a05ab0
3 changed files with 37 additions and 27 deletions

View File

@@ -273,6 +273,11 @@ exports[`<Profile/> renders correctly 1`] = `
<br />
<p
class="text-center points"
>
profile.total-points
</p>
</div>
<div
class="spacer"

View File

@@ -8,6 +8,7 @@ import { Col, Row } from '@freecodecamp/react-bootstrap';
import React from 'react';
import type { TFunction } from 'i18next';
import { useTranslation } from 'react-i18next';
import type { User } from '../../../redux/prop-types';
import envData from '../../../../../config/env.json';
import { getLangCode } from '../../../../../config/i18n';
@@ -21,21 +22,23 @@ const { clientLocale } = envData;
const localeCode = getLangCode(clientLocale);
interface CamperProps {
about: string;
githubProfile: string;
isDonating: boolean;
joinDate: string;
linkedin: string;
location: string;
name: string;
picture: string;
points: number | null;
twitter: string;
username: string;
website: string;
yearsTopContributor: string[];
}
export type CamperProps = Pick<
User,
| 'about'
| 'githubProfile'
| 'isDonating'
| 'linkedin'
| 'points'
| 'username'
| 'twitter'
| 'yearsTopContributor'
| 'location'
| 'website'
| 'picture'
| 'name'
| 'joinDate'
| 'twitter'
>;
function joinArray(array: string[], t: TFunction): string {
return array.reduce((string, item, index, array) => {
@@ -124,11 +127,9 @@ function Camper({
</div>
)}
<br />
{typeof points === 'number' ? (
<p className='text-center points'>
{t('profile.total-points', { count: points })}
</p>
) : null}
<p className='text-center points'>
{t('profile.total-points', { count: points })}
</p>
</div>
);
}

View File

@@ -12,6 +12,7 @@ import { withTranslation } from 'react-i18next';
import isURL from 'validator/lib/isURL';
import { FullWidthRow, Spacer } from '../helpers';
import BlockSaveButton from '../helpers/form/block-save-button';
import type { CamperProps } from '../profile/components/camper';
import SoundSettings from './sound';
import ThemeSettings, { Themes } from './theme';
import UsernameSettings from './username';
@@ -25,13 +26,17 @@ type FormValues = {
about: string;
};
type AboutProps = {
about: string;
type AboutProps = Omit<
CamperProps,
| 'linkedin'
| 'joinDate'
| 'isDonating'
| 'githubProfile'
| 'twitter'
| 'website'
| 'yearsTopContributor'
> & {
currentTheme: Themes;
location: string;
name: string;
picture: string;
points: number;
sound: boolean;
keyboardShortcuts: boolean;
submitNewAbout: (formValues: FormValues) => void;
@@ -39,7 +44,6 @@ type AboutProps = {
toggleNightMode: (theme: Themes) => void;
toggleSoundMode: (sound: boolean) => void;
toggleKeyboardShortcuts: (keyboardShortcuts: boolean) => void;
username: string;
};
type AboutState = {