Skip to content

Commit

Permalink
Fix issues with correct props and fix broken stories
Browse files Browse the repository at this point in the history
  • Loading branch information
Graeme Houston committed Aug 20, 2024
1 parent 4600e48 commit 79cd2d8
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 64 deletions.
56 changes: 42 additions & 14 deletions lib/components/atoms/TileContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import {
BadgeTile,
BannerTile,
ContentTile,
PointsTile,
RewardCategoryTile,
RewardTile,
TierTile,
} from "@/components/organisms";
import { Tile, TileType } from "@/types/tile";
import {
BadgeTileConfig,
BannerTileConfig,
ContentTileConfig,
PointsTileConfig,
RewardCategoryTileConfig,
RewardTileConfig,
TierTileConfig,
Tile,
TileType,
} from "@/types/tile";
import React from "react";
import { StyleSheet, View } from "react-native";

Expand All @@ -17,20 +28,37 @@ type TileContainerProps = {
const TileContainer: React.FC<TileContainerProps> = ({ tiles }) => {
const renderTile = (tile: Tile) => {
switch (tile.type) {
case TileType.Tier:
return <TierTile tile={tile} />;
case TileType.Points:
return <PointsTile tile={tile} />;
case TileType.Content:
return <ContentTile tile={tile} />;
case TileType.Reward:
return <RewardTile tile={tile} />;
case TileType.Badge:
return <BadgeTile tile={tile} />;
case TileType.RewardCategory:
return <RewardCategoryTile tile={tile} />;
case TileType.Banner: {
const config = tile.configuration as BannerTileConfig;
return <BannerTile configuration={config} />;
}
case TileType.Points: {
const config = tile.configuration as PointsTileConfig;
return <PointsTile configuration={config} />;
}
case TileType.Content: {
const config = tile.configuration as ContentTileConfig;
return <ContentTile configuration={config} />;
}
case TileType.Reward: {
const config = tile.configuration as RewardTileConfig;
return <RewardTile configuration={config} />;
}
case TileType.Badge: {
const config = tile.configuration as BadgeTileConfig;
return <BadgeTile configuration={config} />;
}
case TileType.RewardCategory: {
const config = tile.configuration as RewardCategoryTileConfig;
// @ts-ignore we know this is wrong for the time being.
return <RewardCategoryTile configuration={config} />;
}
case TileType.Tier: {
const config = tile.configuration as TierTileConfig;
return <TierTile configuration={config} />;
}
default:
return null;
throw new Error(`Unsupported tile type: ${tile.type}`);
}
};

Expand Down
4 changes: 2 additions & 2 deletions lib/components/molecules/Carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const Carousel: React.FC<CarouselProps> = ({ section }) => {
snapToAlignment="start"
>
{bannerTiles.map((tile: Tile, index: number) => {
const bannerConfig = tile.configuration as BannerTileConfig;
const configuration = tile.configuration as BannerTileConfig;
return (
<View
key={index}
Expand All @@ -104,7 +104,7 @@ const Carousel: React.FC<CarouselProps> = ({ section }) => {
},
]}
>
<BannerTile bannerConfig={bannerConfig} />
<BannerTile configuration={configuration} />
</View>
);
})}
Expand Down
17 changes: 7 additions & 10 deletions lib/components/organisms/BadgeTile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import React from 'react';
import { View } from 'react-native';
import { BadgeTileConfig } from "@/types/tile";
import React from "react";
import { View } from "react-native";

type BadgeTileProps = {
// Define your props here
}
configuration: BadgeTileConfig;
};

const BadgeTile: React.FC<BadgeTileProps> = () => {
return (
<View>
{/* Your component code here */}
</View>
);
const BadgeTile: React.FC<BadgeTileProps> = ({ configuration }) => {
return <View>{/* Your component code here */}</View>;
};

export default BadgeTile;
2 changes: 1 addition & 1 deletion lib/components/organisms/BannerTile/BannerTile.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Template: StoryFn<typeof BannerTile> = (args) => <BannerTile {...args} />;

export const Default = Template.bind({});
Default.args = {
bannerConfig: {
configuration: {
imageUrl:
"https://cdn.pixabay.com/photo/2014/06/03/19/38/board-361516_1280.jpg",
title: "Summer Sale",
Expand Down
23 changes: 12 additions & 11 deletions lib/components/organisms/BannerTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import React from "react";
import { Image, Linking, StyleSheet, View } from "react-native";

type BannerTileProps = {
bannerConfig: BannerTileConfig;
configuration: BannerTileConfig;
};

const BannerTile: React.FC<BannerTileProps> = ({ bannerConfig }) => {
const BannerTile: React.FC<BannerTileProps> = ({ configuration }) => {
const { theme } = useTheme();
const { imageUrl, title, description, ctaText, ctaLink } = configuration;

const handleLinkPress = async (url: string) => {
if (!url) return;
Expand All @@ -26,32 +27,32 @@ const BannerTile: React.FC<BannerTileProps> = ({ bannerConfig }) => {
},
]}
>
{bannerConfig.imageUrl && (
{imageUrl && (
<View style={styles.imageContainer}>
<Image
source={{ uri: bannerConfig.imageUrl }}
source={{ uri: imageUrl }}
style={styles.image}
resizeMode="cover"
onError={(error) => console.error("Image loading error:", error)}
/>
</View>
)}
<View style={styles.slideContent}>
{bannerConfig.title && (
{title && (
<Text variant="title" style={styles.title} isSurface={true}>
{bannerConfig.title}
{title}
</Text>
)}
{bannerConfig.description && (
{description && (
<Text variant="body" style={styles.description} isSurface={true}>
{bannerConfig.description}
{description}
</Text>
)}
{bannerConfig.ctaText && (
{ctaText && (
<Button
title={bannerConfig.ctaText}
title={ctaText}
variant="accent"
onPress={() => handleLinkPress(bannerConfig.ctaLink as string)}
onPress={() => handleLinkPress(ctaLink as string)}
/>
)}
</View>
Expand Down
5 changes: 3 additions & 2 deletions lib/components/organisms/ContentTile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ContentTileConfig } from "@/types/tile";
import React from "react";
import { View } from "react-native";

type ContentTileProps = {
// Define your props here
configuration: ContentTileConfig;
};

const ContentTile: React.FC<ContentTileProps> = () => {
const ContentTile: React.FC<ContentTileProps> = ({ configuration }) => {
return <View>{/* Your component code here */}</View>;
};

Expand Down
17 changes: 7 additions & 10 deletions lib/components/organisms/PointsTile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import React from 'react';
import { View } from 'react-native';
import { PointsTileConfig } from "@/types/tile";
import React from "react";
import { View } from "react-native";

type PointsTileProps = {
// Define your props here
}
configuration: PointsTileConfig;
};

const PointsTile: React.FC<PointsTileProps> = () => {
return (
<View>
{/* Your component code here */}
</View>
);
const PointsTile: React.FC<PointsTileProps> = ({ configuration }) => {
return <View>{/* Your component code here */}</View>;
};

export default PointsTile;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Template: StoryFn<typeof RewardCategoryTile> = (args) => (

export const Default = Template.bind({});
Default.args = {
rewardData: {
configuration: {
allowDecorationOverlay: true,
id: "9cb2cc08-e033-4200-86a7-95a03ba09462",
createdAt: "2018-06-08T08:57:47.198Z",
Expand All @@ -29,7 +29,7 @@ Default.args = {

export const LongCategoryName = Template.bind({});
LongCategoryName.args = {
rewardData: {
configuration: {
allowDecorationOverlay: true,
id: "9cb2cc08-e033-4200-86a7-95a03ba09462",
createdAt: "2018-06-08T08:57:47.198Z",
Expand All @@ -45,7 +45,7 @@ LongCategoryName.args = {

export const NoDecorationOverlay = Template.bind({});
NoDecorationOverlay.args = {
rewardData: {
configuration: {
allowDecorationOverlay: false,
id: "9cb2cc08-e033-4200-86a7-95a03ba09462",
createdAt: "2018-06-08T08:57:47.198Z",
Expand Down
10 changes: 5 additions & 5 deletions lib/components/organisms/RewardCategoryTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "react-native";

type RewardCategoryTileProps = {
rewardData: {
configuration: {
allowDecorationOverlay: boolean;
id: string;
createdAt: string;
Expand All @@ -25,10 +25,10 @@ type RewardCategoryTileProps = {
};

const RewardCategoryTile: React.FC<RewardCategoryTileProps> = ({
rewardData,
configuration,
}) => {
const { theme } = useTheme();
const { allowDecorationOverlay } = rewardData;
const { allowDecorationOverlay, name, pictureUrl } = configuration;

// TODO: Add logic to fetch the reward data from the API at the moment just using fake data to style components

Expand All @@ -49,12 +49,12 @@ const RewardCategoryTile: React.FC<RewardCategoryTileProps> = ({
ellipsizeMode="tail"
numberOfLines={1}
>
{rewardData.name}
{name}
</Text>
</View>
)}
<Image
source={{ uri: rewardData.pictureUrl }}
source={{ uri: pictureUrl }}
style={styles.image}
resizeMode="cover"
onError={(error) => console.error("Image loading error:", error)}
Expand Down
5 changes: 3 additions & 2 deletions lib/components/organisms/RewardTile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { RewardTileConfig } from "@/types/tile";
import React from "react";
import { View } from "react-native";

type RewardTileProps = {
// Define your props here
configuration: RewardTileConfig;
};

const RewardTile: React.FC<RewardTileProps> = () => {
const RewardTile: React.FC<RewardTileProps> = ({ configuration }) => {
return <View>{/* Your component code here */}</View>;
};

Expand Down
10 changes: 6 additions & 4 deletions lib/components/organisms/TierTile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { Text } from "@/components/atoms";
import { ProgressIndicator } from "@/components/molecules";
import { useTheme } from "@/context/ThemeContext";
import { Tile } from "@/types/tile";
import { TierTileConfig } from "@/types/tile";
import { useResponsiveScale } from "@/utils/responsiveScaling";
import { sizes } from "@/utils/styling";
import React from "react";
import { View } from "react-native";
type TierTileProps = {
configuration: TierTileConfig;
};

const TierTile = (tile: Tile) => {
const TierTile: React.FC<TierTileProps> = ({ configuration }) => {
const { ms } = useResponsiveScale();

if (!tile) return null;
if (!configuration) return null;
const { theme } = useTheme();
const { tileHeight, configuration } = tile;

const tierData = {
name: "Gold",
Expand Down

0 comments on commit 79cd2d8

Please sign in to comment.