summaryrefslogtreecommitdiff
path: root/src/App.jsx
blob: db340dabc58c51b5fe89ca6e40b13bb247e244b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import {useEffect, useState} from "react";
import Entry from "./Entry.jsx";

import {AppBar, Button, Container, Grid, Paper, Typography} from "@mui/material";
import dayjs from "dayjs";
import SalaryInput from "./SalaryInput.jsx";
import Result from "./Result.jsx";
import RemoveCircleIcon from '@mui/icons-material/RemoveCircle';
import AddCircleIcon from '@mui/icons-material/AddCircle';
import Icon from '@mdi/react';
import { mdiGitlab } from '@mdi/js';


function App() {
    const [baseSalary, setBaseSalary] = useState(0);
    const [listEntry, setListEntry] = useState(
        [
            {id: 0, date: dayjs(), start: dayjs().set('hour', 17).set('minute', 30), finish: dayjs().set('hour', 18).set('minute', 30)},
        ]
    );
    const [removeDisabled, setRemoveDisabled] = useState(false);

    useEffect(() => {
        setRemoveDisabled(listEntry.length === 1);
    }, [listEntry]);

    const getLastId = () => {
        const lastEntry = listEntry[listEntry.length - 1];
        return lastEntry.id;
    }

    const handleEntryChange = (entry, updatedAttr) => {
        const updatedEntryList = listEntry.map((entryOnList) => {
            if (entryOnList.id === entry.id) {
                return {...entryOnList, [updatedAttr]: entry[updatedAttr]}
            }
            return entryOnList;
        });
        setListEntry(updatedEntryList);
    }

    const handleBaseSalaryChange = (baseSalaryInput) => {
        setBaseSalary(baseSalaryInput);
    }

    const addToList = () => {
        const newEntry = {
            id: getLastId() + 1,
            date: dayjs(),
            start: dayjs(),
            finish: dayjs()
        }
        setListEntry((currentList) => [...currentList, newEntry]);
    }

    const removeFromList = (id) => {
        setListEntry((currentList) => {
            return currentList.filter((en) => en.id !== id);
        });
    }

    // raimu kurang gawean
    return (
        <>
            <Container>
                <AppBar position="sticky" sx={{padding: '10px 0'}}>
                    <Typography
                        variant='h4'
                        sx={{
                            ml: 5,
                            display: { xs: 'none', md: 'flex' },
                            letterSpacing: '.3rem',
                            color: 'inherit',
                            textDecoration: 'none',
                        }}
                    >Overtime Calculator</Typography>
                </AppBar>
                <Typography variant='overline' display='block' align='center'>🤑🤑 Sudahkah anda lembur hari ini?
                    🤑🤑</Typography>
                <Paper sx={{margin: '10px 0', padding: '20px'}}>
                    <ul>
                        <li style={{listStyle: 'none', margin: '20px 0'}}>
                            <SalaryInput handleBaseSalaryChange={handleBaseSalaryChange}/>
                        </li>
                        {listEntry.map((entry) => {
                            return (
                                <div key={entry.id} style={{display: 'flex', gap: '10px', marginBottom: '10px'}}>
                                    <li style={{listStyle: 'none'}} key={entry.id}>
                                        <Entry
                                            propId={entry.id}
                                            propDate={entry.date}
                                            propStart={entry.start}
                                            propFinish={entry.finish}
                                            handleEntryChange={handleEntryChange}
                                        />
                                    </li>
                                    <Button
                                        disabled={removeDisabled}
                                        variant="outlined"
                                        onClick={() => removeFromList(entry.id)}
                                    ><RemoveCircleIcon /></Button>
                                    {
                                        entry.id === getLastId() ?
                                            <Button
                                                variant="outlined"
                                                onClick={addToList}
                                            ><AddCircleIcon /></Button>
                                            : null
                                    }
                                </div>
                            )
                        })}
                    </ul>
                </Paper>
                <Grid container columnSpacing='5px' sx={{mb: '20px'}}>
                    <Grid item xs={6}>
                        <Paper sx={{padding: '10px', minHeight: '100%'}}>
                            <Result listEntry={listEntry} baseSalary={baseSalary}/>
                        </Paper>
                    </Grid>
                    <Grid item xs={6}>
                        <Paper sx={{padding: '10px', minHeight: '100%'}}>
                            <ul>
                                <li><Typography>Disclaimer: keakuratan tidak terjamin</Typography></li>
                                <li><Typography>Sudah termasuk perhitungan lembur akhir pekan</Typography></li>
                                <li><Typography>Belum termasuk libur nasional (todo)</Typography></li>
                                <li><Typography>Belum termasuk versi 6 hari kerja (todo)</Typography></li>
                                <li><Typography>UI belum responsive (todo)</Typography></li>
                            </ul>
                            <div style={{textAlign: 'center'}}>
                                <a href='https://gitlab.com/rosyidharyadi/overreact' target='_blank'>
                                    <Icon path={mdiGitlab}
                                          title="Repository"
                                          size={2}
                                          // horizontal
                                          // vertical
                                          // rotate={90}
                                          color="blue"
                                          spin
                                    />
                                </a>
                            </div>
                        </Paper>
                    </Grid>
                </Grid>
            </Container>
        </>
    )
}

export default App