Skip to content

Commit

Permalink
Merge pull request #4077 from webkom/success-card
Browse files Browse the repository at this point in the history
  • Loading branch information
LudvigHz committed Aug 7, 2023
2 parents 8c59360 + fe54453 commit 251fb7d
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 53 deletions.
30 changes: 25 additions & 5 deletions app/components/Card/Card.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
border-radius: var(--border-radius-lg);
}

.header {
font-weight: 600;
font-size: var(--font-size-lg);
line-height: 1.3;
}

.shadow {
box-shadow: var(--shadow-sm);
}
Expand Down Expand Up @@ -60,11 +66,25 @@ html[data-theme='dark'] .danger a:hover {
}

.infoIcon {
color: var(--color-blue-8);
color: var(--color-blue-7);
}

.header {
font-weight: 600;
font-size: var(--font-size-lg);
line-height: 1.3;
.success {
margin: 20px 0;
background-color: var(--color-green-2);
border: 1.5px solid var(--color-green-7);
color: var(--color-green-7);
}

.success a {
color: var(--color-green-8);
text-decoration: underline;

&:hover {
color: var(--color-green-7);
}
}

.successIcon {
color: var(--color-green-7);
}
45 changes: 25 additions & 20 deletions app/components/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Flex from 'app/components/Layout/Flex';
import styles from './Card.css';
import type { HTMLAttributes, ReactNode } from 'react';

type Severity = 'danger' | 'info' | 'success';

type CardHeaderProps = {
children: ReactNode;
className?: string;
Expand All @@ -14,25 +16,33 @@ const CardHeader = ({ children, className }: CardHeaderProps) => (
);

type CardContentProps = {
severity?: Severity;
children: ReactNode;
danger?: boolean;
info?: boolean;
};

const CardContent = ({ children, danger, info }: CardContentProps) => {
const CardContent = ({ children, severity }: CardContentProps) => {
let icon;
if (danger) {
icon = <Icon name="alert-circle-outline" className={styles.warningIcon} />;
}

if (info) {
icon = (
<Icon name="information-circle-outline" className={styles.infoIcon} />
);
switch (severity) {
case 'danger':
icon = (
<Icon name="alert-circle-outline" className={styles.warningIcon} />
);
break;
case 'info':
icon = (
<Icon name="information-circle-outline" className={styles.infoIcon} />
);
break;
case 'success':
icon = (
<Icon name="checkmark-circle-outline" className={styles.successIcon} />
);
break;
}

return icon !== undefined ? (
<Flex gap={20} className={styles.cardWithSeverity}>
<Flex gap={20}>
{icon}
<Flex column>{children}</Flex>
</Flex>
Expand All @@ -46,8 +56,7 @@ type Props = {
shadow?: boolean;
hideOverflow?: boolean;
isHoverable?: boolean;
danger?: boolean;
info?: boolean;
severity?: Severity;
} & HTMLAttributes<HTMLDivElement>;

function Card({
Expand All @@ -56,8 +65,7 @@ function Card({
shadow = true,
hideOverflow = false,
isHoverable = false,
danger = false,
info = false,
severity,
...htmlAttributes
}: Props) {
return (
Expand All @@ -67,17 +75,14 @@ function Card({
styles.card,
shadow && styles.shadow,
isHoverable && styles.isHoverable,
danger && styles.danger,
info && styles.info
severity && styles[severity]
)}
style={{
overflow: hideOverflow ? 'hidden' : 'initial',
}}
{...htmlAttributes}
>
<CardContent danger={danger} info={info}>
{children}
</CardContent>
<CardContent severity={severity}>{children}</CardContent>
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/components/PhotoUploadStatus/PhotoUploadStatus.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
cursor: pointer;
}

.successMessage {
color: var(--color-green-6);
.header {
width: 80%;
}
33 changes: 20 additions & 13 deletions app/components/PhotoUploadStatus/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Fragment } from 'react';
import { connect } from 'react-redux';
import { Gallery } from 'app/actions/ActionTypes';
import Card from 'app/components/Card';
Expand Down Expand Up @@ -31,29 +30,37 @@ const UploadStatusCard = ({
hideUploadStatus,
}: Props) => {
if (!uploadStatus.showStatus) return null;

const uploadDone =
uploadStatus.successCount + uploadStatus.failCount ===
uploadStatus.imageCount;
const hasFailedUploads = uploadStatus.failCount !== 0;
const word = uploadStatus.successCount === 1 ? 'bilde' : 'bilder';

return (
<Card className={styles.photoUploadStatus}>
<Card
severity={!uploadDone ? 'info' : hasFailedUploads ? 'danger' : 'success'}
className={styles.photoUploadStatus}
>
<Icon className={styles.close} onClick={hideUploadStatus} name="close" />

{uploadDone ? (
<Fragment>
<h3 className={styles.successMessage}>
{uploadStatus.successCount} {word} ble lastet opp{' '}
</h3>
</Fragment>
<Card.Header className={styles.header}>
{uploadStatus.successCount > 1 ? uploadStatus.successCount : 'Ingen'}{' '}
{hasFailedUploads ? `av ${uploadStatus.imageCount}` : ''}{' '}
{uploadStatus.successCount === 1 ? 'bilde' : 'bilder'} ble lastet opp
</Card.Header>
) : (
<Fragment>
<h3>Laster opp bilder ...</h3>
<>
<Card.Header>
Laster opp {uploadStatus.imageCount > 1 ? 'bildene' : 'bildet'} ...
</Card.Header>
<p>
<b>Status</b>: {uploadStatus.successCount} av{' '}
{uploadStatus.imageCount}
</p>
</Fragment>
</>
)}

{hasFailedUploads && (
<Tooltip
content={
Expand All @@ -70,13 +77,13 @@ const UploadStatusCard = ({
</Flex>
}
>
<b>Antall feil</b>: {uploadStatus.failCount}
{uploadStatus.failCount} feil
</Tooltip>
)}

{lastImage && (
<Image
alt="Last"
alt="Siste bilde"
style={{
width: 250,
height: 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ let AnnouncementsCreate = ({
Opprett og send
</Button>

<Card info>
<Card severity="info">
Du kan velge å sende kunngjøringen med en gang, eller lagre den
og sende den senere fra listen nedenfor.
</Card>
Expand Down
2 changes: 1 addition & 1 deletion app/routes/bdb/components/BdbDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ export default class BdbDetail extends Component<Props, State> {
marginBottom: '10px',
}}
>
<Card info>
<Card severity="info">
<Card.Header>Tips</Card.Header>
Du kan endre semestere ved å trykke på dem i listen!
</Card>
Expand Down
2 changes: 1 addition & 1 deletion app/routes/bdb/components/BdbPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export default class BdbPage extends Component<Props, State> {
filters={this.state.filters}
/>

<Card info>
<Card severity="info">
<Card.Header>Tips</Card.Header>
Du kan endre semestere ved å trykke på dem i listen!
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ const CompanyInterestPage = (props: Props) => {
</Link>
)}
</FlexRow>
<Card info>
<Card severity="info">
{labels.subHeading[language]}
<a href={'mailto:bedriftskontakt@abakus.no'}>
bedriftskontakt@abakus.no
Expand Down
2 changes: 1 addition & 1 deletion app/routes/contact/components/ContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ContactForm = (props: Props) => {
Hovedstyret, enten du har spørsmål, tilbakemeldinger, eller bare ønsker
å dele informasjon med oss.
</p>
<Card info>
<Card severity="info">
<p>
Dersom du ønsker å varsle om kritikkverdige forhold, vennligst benytt
vår{' '}
Expand Down
2 changes: 1 addition & 1 deletion app/routes/events/components/EventAttendeeStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const EventAttendeeStatistics = ({
return (
<>
{isEventFromPreviousSemester(eventStartTime) && (
<Card danger>
<Card severity="danger">
<span>
Dette arrangementet er fra et tidligere semester, og kan derfor ha
feil fordeling av klassetrinn og gruppetilhørighet. Dette er fordi
Expand Down
2 changes: 1 addition & 1 deletion app/routes/events/components/EventDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export default class EventDetail extends Component<Props, State> {
{'unansweredSurveys' in event &&
event.unansweredSurveys?.length > 0 &&
!event.isAdmitted ? (
<Card danger>
<Card severity="danger">
<p>
Du kan ikke melde deg på dette arrangementet fordi du har
ubesvarte spørreundersøkelser. Gå til lenkene under for å
Expand Down
4 changes: 2 additions & 2 deletions app/routes/events/components/JoinEventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ const JoinEventForm = (props: Props) => {
<div>Du kan ikke melde deg på dette arrangementet.</div>
)}
{sumPenalties(penalties) > 0 && event.heedPenalties && (
<Card danger>
<Card severity="danger">
<Card.Header>NB!</Card.Header>
<p>
{sumPenalties(penalties) > 2
Expand All @@ -377,7 +377,7 @@ const JoinEventForm = (props: Props) => {
{!disabledForUser &&
event.useContactTracing &&
!currentUser.phoneNumber && (
<Card danger>
<Card severity="danger">
<Card.Header>NB!</Card.Header>
<p>
Du må legge til telefonnummer for å melde deg på dette
Expand Down
5 changes: 3 additions & 2 deletions app/routes/events/components/StripeElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { loadStripe } from '@stripe/stripe-js';
import { Component, useState, useEffect, useCallback } from 'react';
import Button from 'app/components/Button';
import Card from 'app/components/Card';
import LoadingIndicator from 'app/components/LoadingIndicator';
import config from 'app/config';
import type { EventRegistrationPaymentStatus, Event } from 'app/models';
Expand Down Expand Up @@ -348,13 +349,13 @@ class PaymentForm extends Component<FormProps, FormState> {
render() {
const { success, error, loading } = this.state;
return success ? (
<div className={stripeStyles.success}>
<Card severity="success">
{`Din betaling på ${
this.props.event.price
? (this.props.event.price / 100).toFixed(2).replace('.', ',')
: ''
} kr ble godkjent.`}
</div>
</Card>
) : (
<>
{loading && <LoadingIndicator loading />}
Expand Down
4 changes: 3 additions & 1 deletion app/routes/photos/components/GalleryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ class GalleryEditor extends Component<Props, State> {
/>
<Flex>
{isNew ? (
<Card info>For å legge inn bilder må du først lage albumet!</Card>
<Card severity="info">
For å legge inn bilder må du først lage albumet!
</Card>
) : (
<GalleryComponent
photos={pictures}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ const SurveyEditor = ({
)}
</TypedLegoForm>

<Card info>
<Card severity="info">
<span>
Deltagerene på arrangementet vil få e-post med link til
spørreundersøkelsen når den aktiveres (
Expand Down

0 comments on commit 251fb7d

Please sign in to comment.