️ feat: Add isComingSoon property to templates and handle click event in TemplateCard component

This commit is contained in:
Wahyu Kurniawan 2024-02-28 14:45:27 +07:00
parent 102d87d9dd
commit 392377d6ae
No known key found for this signature in database
GPG Key ID: 040A1549143A8E33
2 changed files with 38 additions and 10 deletions

View File

@ -4,29 +4,34 @@ export default [
name: 'Progressive Web App (PWA)', name: 'Progressive Web App (PWA)',
icon: 'pwa', icon: 'pwa',
repoFullName: `${process.env.REACT_APP_GITHUB_PWA_TEMPLATE_REPO}`, repoFullName: `${process.env.REACT_APP_GITHUB_PWA_TEMPLATE_REPO}`,
isComingSoon: false,
}, },
{ {
id: '2', id: '2',
name: 'Image Upload PWA', name: 'Image Upload PWA',
icon: 'pwa', icon: 'pwa',
repoFullName: `${process.env.REACT_APP_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO}`, repoFullName: `${process.env.REACT_APP_GITHUB_IMAGE_UPLOAD_PWA_TEMPLATE_REPO}`,
isComingSoon: false,
}, },
{ {
id: '3', id: '3',
name: 'Kotlin', name: 'Kotlin',
icon: 'kotlin', icon: 'kotlin',
repoFullName: '', repoFullName: '',
isComingSoon: false,
}, },
{ {
id: '4', id: '4',
name: 'React Native', name: 'React Native',
icon: 'react-native', icon: 'react-native',
repoFullName: '', repoFullName: '',
isComingSoon: false,
}, },
{ {
id: '5', id: '5',
name: 'Swift', name: 'Swift',
icon: 'swift', icon: 'swift',
repoFullName: '', repoFullName: '',
isComingSoon: true,
}, },
]; ];

View File

@ -9,12 +9,14 @@ import { Tag } from 'components/shared/Tag';
import React, { ComponentPropsWithoutRef, useCallback } from 'react'; import React, { ComponentPropsWithoutRef, useCallback } from 'react';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { useToast } from 'components/shared/Toast'; import { useToast } from 'components/shared/Toast';
import { cn } from 'utils/classnames';
export interface TemplateDetail { export interface TemplateDetail {
id: string; id: string;
name: string; name: string;
icon: string; icon: string;
repoFullName?: string; repoFullName?: string;
isComingSoon?: boolean;
} }
export interface TemplateCardProps extends ComponentPropsWithoutRef<'div'> { export interface TemplateCardProps extends ComponentPropsWithoutRef<'div'> {
@ -27,6 +29,14 @@ export const TemplateCard = ({ template, isGitAuth }: TemplateCardProps) => {
const navigate = useNavigate(); const navigate = useNavigate();
const handleClick = useCallback(() => { const handleClick = useCallback(() => {
if (template?.isComingSoon) {
return toast({
id: 'coming-soon',
title: 'This template is coming soon',
variant: 'info',
onDismiss: dismiss,
});
}
if (isGitAuth) { if (isGitAuth) {
return navigate(`/template?templateId=${template.id}`); return navigate(`/template?templateId=${template.id}`);
} }
@ -36,27 +46,40 @@ export const TemplateCard = ({ template, isGitAuth }: TemplateCardProps) => {
variant: 'error', variant: 'error',
onDismiss: dismiss, onDismiss: dismiss,
}); });
}, [isGitAuth, navigate, template.id, toast]); }, [isGitAuth, navigate, template, toast]);
return ( return (
<div className="flex items-center gap-3 px-3 py-3 bg-base-bg-alternate rounded-2xl"> <button
className={cn(
'flex items-center gap-3 px-3 py-3 bg-base-bg-alternate hover:bg-base-bg-emphasized rounded-2xl group',
{
'cursor-default': template?.isComingSoon,
},
)}
onClick={handleClick}
>
{/* Icon */} {/* Icon */}
<div className="px-1 py-1 rounded-xl bg-base-bg border border-border-interactive shadow-card"> <div className="px-1 py-1 rounded-xl bg-base-bg border border-border-interactive/10 shadow-card-sm">
<TemplateIcon type={template.icon as TemplateIconType} /> <TemplateIcon type={template.icon as TemplateIconType} />
</div> </div>
{/* Name */} {/* Name */}
<p className="flex-1 text-sm tracking-tighter text-elements-high-em"> <p className="flex flex-1 text-sm tracking-tighter text-elements-high-em">
{template.name} {template.name}
</p> </p>
{template?.repoFullName ? ( {template?.isComingSoon ? (
<Button variant="tertiary" size="sm" iconOnly onClick={handleClick}>
<ArrowRightCircleIcon />
</Button>
) : (
<Tag size="xs" type="neutral" leftIcon={<ClockOutlineIcon />}> <Tag size="xs" type="neutral" leftIcon={<ClockOutlineIcon />}>
Soon Soon
</Tag> </Tag>
) : (
<Button
variant="tertiary"
size="sm"
iconOnly
className="group-hover:flex hidden"
>
<ArrowRightCircleIcon />
</Button>
)} )}
</div> </button>
); );
}; };