-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
753 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
@import '~typeface-roboto/index.css'; | ||
@import '~typeface-roboto/index.css'; | ||
|
||
@import '~flag-icon-css/css/flag-icon.min.css'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react'; | ||
import TableContainer from '@material-ui/core/TableContainer'; | ||
import Table from '@material-ui/core/Table'; | ||
import TableBody from '@material-ui/core/TableBody'; | ||
import TableRow from '@material-ui/core/TableRow'; | ||
import TableCell from '@material-ui/core/TableCell'; | ||
import {useTranslation} from 'react-i18next'; | ||
import {Contact as IContact} from 'sms77-client'; | ||
|
||
export type ContactProps = { | ||
contact: IContact | ||
} | ||
|
||
export const Contact = ({contact}: ContactProps) => { | ||
const {t} = useTranslation('contacts'); | ||
|
||
return <TableContainer style={{marginBottom: '1em'}}> | ||
<Table> | ||
<TableBody> | ||
<TableRow> | ||
<TableCell component='th' scope='row'> | ||
{t('nick')} | ||
</TableCell> | ||
|
||
<TableCell align='right'> | ||
{contact.nick} | ||
</TableCell> | ||
</TableRow> | ||
|
||
<TableRow> | ||
<TableCell component='th' scope='row'> | ||
{t('email')} | ||
</TableCell> | ||
|
||
<TableCell align='right'> | ||
{contact.email} | ||
</TableCell> | ||
</TableRow> | ||
|
||
<TableRow> | ||
<TableCell component='th' scope='row'> | ||
{t('id')} | ||
</TableCell> | ||
|
||
<TableCell align='right'> | ||
{contact.id} | ||
</TableCell> | ||
</TableRow> | ||
|
||
<TableRow> | ||
<TableCell component='th' scope='row'> | ||
{t('number')} | ||
</TableCell> | ||
|
||
<TableCell align='right'> | ||
{contact.number} | ||
</TableCell> | ||
</TableRow> | ||
</TableBody> | ||
</Table> | ||
</TableContainer>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, {useEffect, useState} from 'react'; | ||
import {useTranslation} from 'react-i18next'; | ||
import {useDispatch} from 'react-redux'; | ||
import Sms77Client, {Contact as Sms77Contact} from 'sms77-client'; | ||
import Button from '@material-ui/core/Button'; | ||
import Grid from '@material-ui/core/Grid'; | ||
|
||
import {Contact} from './Contact'; | ||
import {LocalStore} from '../../util/LocalStore'; | ||
import {addSnackbar, setNav, setTo} from '../../store/actions'; | ||
import {notify} from '../../util/notify'; | ||
|
||
export const Contacts = () => { | ||
const {t} = useTranslation('contacts'); | ||
const dispatch = useDispatch(); | ||
const apiKey = LocalStore.get('options.apiKey'); | ||
const [contacts, setContacts] = useState<Sms77Contact[]>(LocalStore.get('contacts') as Sms77Contact[]); | ||
|
||
useEffect(() => { | ||
if ('' === apiKey) { | ||
dispatch(addSnackbar(t('pleaseSetApiKey'))); | ||
|
||
dispatch(setNav('options')); | ||
} else { | ||
getAndStore() | ||
.then() | ||
.catch(e => notify(e.toString ? e.toString() : JSON.stringify(e))); | ||
} | ||
}, []); | ||
|
||
const getAndStore = async () => { | ||
let contacts = LocalStore.get('contacts') as Sms77Contact[]; | ||
|
||
if (!Array.isArray(contacts)) { | ||
const client = new Sms77Client(apiKey as string); | ||
|
||
contacts = await client.contacts({action: 'read', json: true,}) as Sms77Contact[]; | ||
|
||
LocalStore.set('contacts', contacts); | ||
|
||
setContacts(contacts); | ||
} | ||
}; | ||
|
||
return <> | ||
<div style={{display: 'flex', justifyContent: 'space-between'}}> | ||
<h1 style={{display: 'inline-flex'}}>{t('contacts')}</h1> | ||
|
||
<Button onClick={() => getAndStore()}> | ||
{t('reload')} | ||
</Button> | ||
</div> | ||
|
||
{ | ||
Array.isArray(contacts) | ||
? <Grid spacing={2} container justify='center' alignItems='center'> | ||
{contacts.map((c, i) => <Grid key={i} item md={6} lg={4}> | ||
<Button size='small' fullWidth disabled={0 === c.number.length} onClick={() => { | ||
dispatch(setTo(c.number)); | ||
dispatch(setNav('send')); | ||
}} variant='outlined'>{t('send')}</Button> | ||
|
||
<Contact key={i} contact={c}/> | ||
</Grid>)} | ||
</Grid> | ||
: <p>{t('noEntries')}</p> | ||
} | ||
</>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react'; | ||
import {CountryPricing} from 'sms77-client'; | ||
|
||
export type CountryFlagProps = { | ||
pricing: CountryPricing | ||
} | ||
|
||
export const CountryFlag = ({pricing}: CountryFlagProps) => { | ||
const toFlag = () => pricing.countryCode | ||
.replace('BL/GF/GP/M', 'FR') //TODO: add GP & GF as they have individual non-French flags? | ||
.replace('YT/RE', 'YT') | ||
.replace('SH, TA', 'SH') | ||
.toLowerCase(); | ||
|
||
const flag = pricing.countryCode ? toFlag() : 'eu'; | ||
|
||
const className = `flag-icon flag-icon-${flag}`; | ||
|
||
return <span className={className}/>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.