@autobusal/order-confirm 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ import { TFunction } from 'i18next';
2
+ import { useEffect } from 'react';
3
+ import { useSearchParams, useParams, useNavigate } from 'react-router-dom';
4
+ import { AiOutlineCheck } from 'react-icons/ai';
5
+ import { BiErrorAlt } from 'react-icons/bi';
6
+ import { IoReturnUpBackOutline } from 'react-icons/io5';
7
+ // import { useAuthContext } from '../../../context/Auth';
8
+ import { Meta, Button } from '@autobusal/common';
9
+ import Reason from './Reason';
10
+ import { Title, Actions } from './styles';
11
+
12
+ interface Props {
13
+ t: TFunction<'common'>
14
+ }
15
+
16
+ const OrderConfirm = ({ t }: Props): (JSX.Element | null) => {
17
+ const [ searchParams ] = useSearchParams();
18
+
19
+ const { type, order_id } = useParams();
20
+
21
+ const navigate = useNavigate();
22
+
23
+ const message = String(searchParams.get('msg') ?? '');
24
+
25
+ // @todo: sa mearga asta cu userul
26
+ // const { user } = useAuthContext();
27
+
28
+ const isAllowed = ['reserved', 'cancelled', 'purchased'].includes(
29
+ String(type)
30
+ );
31
+
32
+ useEffect(() => {
33
+ if (!isAllowed) {
34
+ navigate('/');
35
+ }
36
+ }, []);
37
+
38
+ if (!isAllowed) {
39
+ return null;
40
+ }
41
+
42
+ const onManage = (): void => {
43
+ navigate(`/viewtrip/${ order_id }`);
44
+ };
45
+
46
+ const onBack = (): void => {
47
+ // const backUrl = user ? '/account' : '/';
48
+
49
+ navigate('/');
50
+ };
51
+
52
+ return (
53
+ <Meta title={ t(`order_confirm.title.${ type }`) } description={ t('order_confirm.meta.description') }>
54
+ <Title>
55
+ { type === 'cancelled' ? <BiErrorAlt /> : <AiOutlineCheck /> }
56
+ { t(`order_confirm.title.${ type }`) }
57
+ </Title>
58
+
59
+ <div className="box" dangerouslySetInnerHTML={{
60
+ __html: t(`order_confirm.content.${ type}`, { order: `<strong>${ order_id }</strong>` })
61
+ }} />
62
+
63
+ <>
64
+ { (type === 'cancelled' && message !== '') && <Reason message={ message } t={ t } /> }
65
+ </>
66
+
67
+ <Actions>
68
+ <Button
69
+ type="button"
70
+ text={ t('order_confirm.manage') }
71
+ noMargin
72
+ onClick={ onManage }
73
+ />
74
+
75
+ <Button
76
+ type="button"
77
+ subtype="secondary"
78
+ text={
79
+ <><IoReturnUpBackOutline /> { t('order_confirm.back') }</>
80
+ }
81
+ noMargin
82
+ onClick={ onBack }
83
+ />
84
+ </Actions>
85
+ </Meta>
86
+ );
87
+ };
88
+
89
+ export default OrderConfirm;
package/Reason.tsx ADDED
@@ -0,0 +1,15 @@
1
+ import { TFunction } from 'i18next';
2
+ import { Cancelled } from './styles';
3
+
4
+ interface Props {
5
+ message: string
6
+ t: TFunction<'common'>
7
+ }
8
+
9
+ const Reason = ({ message, t }: Props): JSX.Element => (
10
+ <Cancelled className="box">
11
+ <strong>{ t('order_confirm.cancelled.title') }:</strong> { message }
12
+ </Cancelled>
13
+ );
14
+
15
+ export default Reason;
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ import OrderConfirm from './OrderConfirm';
2
+
3
+ export default OrderConfirm;
package/package.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "@autobusal/order-confirm",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "index.ts"
6
+ }
package/styles.ts ADDED
@@ -0,0 +1,22 @@
1
+ import styled from 'styled-components';
2
+
3
+ export const Title = styled.h1`
4
+ display: flex;
5
+ gap: 6px;
6
+ align-items: center;
7
+ `;
8
+
9
+ export const Actions = styled.div`
10
+ display: flex;
11
+ gap: 10px;
12
+ justify-content: center;
13
+ margin-top: 15px;
14
+ `;
15
+
16
+ export const Cancelled = styled.div`
17
+ margin-top: 15px;
18
+ padding-top: 8px;
19
+ padding-bottom: 8px;
20
+ color: #FFF;
21
+ background: ${ props => props.theme.font.error };
22
+ `;