-
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
14 changed files
with
433 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,4 @@ yarn-error.* | |
*.tsbuildinfo | ||
|
||
.idea | ||
.env |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { StyleSheet, View } from "react-native"; | ||
import PresenceCard from "../register/precenseCard"; | ||
import { useAtom, useAtomValue } from "jotai"; | ||
import { membersAtom, Slot, slotsAtom } from "../../stores/register"; | ||
import { getStatus, stateAtom } from "../../stores/corvee"; | ||
import { useContext, useEffect, useState } from "react"; | ||
import { Button, Text, useTheme } from "react-native-paper"; | ||
import { CORVEE } from "../../env"; | ||
import AuthContext, { Authed } from "../../auth"; | ||
|
||
export default function Create() { | ||
const slots = useAtomValue(slotsAtom); | ||
const members = useAtomValue(membersAtom); | ||
const [state, setState] = useAtom(stateAtom); | ||
const [loading, setLoading] = useState(false); | ||
const theme = useTheme(); | ||
const authState = useContext(AuthContext); | ||
|
||
const [slot, setSlot] = useState<Slot>(); | ||
|
||
useEffect(() => { | ||
if (!slots || !state) return setSlot(undefined); | ||
|
||
setSlot( | ||
slots.find((slot) => slot.pod === state.pod && slot.name === state.day), | ||
); | ||
}, [slots, state]); | ||
|
||
async function create() { | ||
if (authState.authenticated !== Authed.AUTHENTICATED) return; | ||
|
||
setLoading(true); | ||
const token = await authState.token; | ||
await fetch(`${CORVEE}/api/v1/renew`, { | ||
headers: { | ||
authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
|
||
const state = await getStatus(token); | ||
setLoading(false); | ||
setState(state); | ||
} | ||
|
||
if (!slot) return; | ||
|
||
return ( | ||
<> | ||
<View | ||
style={[ | ||
styles.card, | ||
{ backgroundColor: theme.colors.elevation.level1 }, | ||
]} | ||
> | ||
<Text variant={"titleMedium"} style={styles.text}> | ||
Wie is er aanwezig? | ||
</Text> | ||
<PresenceCard slot={slot} members={members} /> | ||
</View> | ||
<Button mode={"contained"} onPress={create} loading={loading}> | ||
Maak lijst aan | ||
</Button> | ||
</> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
text: { | ||
textAlign: "center", | ||
marginBottom: 15, | ||
}, | ||
card: { | ||
padding: 15, | ||
borderRadius: 15, | ||
flexGrow: 1, | ||
}, | ||
}); |
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,86 @@ | ||
import { Button, Card } from "react-native-paper"; | ||
import { ScrollView, StyleSheet, View } from "react-native"; | ||
import { CorveeProfile, getStatus, stateAtom } from "../../stores/corvee"; | ||
import { useContext, useState } from "react"; | ||
import AuthContext, { Authed } from "../../auth"; | ||
import { CORVEE } from "../../env"; | ||
import { useAtom, useSetAtom } from "jotai"; | ||
|
||
enum Action { | ||
ACKNOWLEDGE = "ack", | ||
ABSENT = "absent", | ||
INSUFFICIENT = "insuff", | ||
} | ||
|
||
export default function Listing({ selected }: { selected: CorveeProfile }) { | ||
const [loading, setLoading] = useState<Set<Action>>(new Set()); | ||
const setState = useSetAtom(stateAtom); | ||
const authState = useContext(AuthContext); | ||
|
||
function action(id: string, action: Action) { | ||
return async function () { | ||
if (authState.authenticated !== Authed.AUTHENTICATED) return; | ||
|
||
setLoading(loading.add(action)); | ||
|
||
const token = await authState.token; | ||
await fetch(`${CORVEE}/api/v1/${action}/${id}`, { | ||
headers: { | ||
authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
|
||
const state = await getStatus(token); | ||
setState(state); | ||
|
||
loading.delete(action); | ||
setLoading(loading); | ||
}; | ||
} | ||
|
||
return ( | ||
<Card key={selected.id}> | ||
<Card.Cover | ||
style={{ aspectRatio: 1, height: undefined }} | ||
source={{ uri: selected.picture }} | ||
/> | ||
<Card.Title title={`${selected.first_name} ${selected.last_name}`} /> | ||
<Card.Actions> | ||
<ScrollView horizontal={true}> | ||
<View style={styles.actions}> | ||
<Button | ||
loading={loading.has(Action.ACKNOWLEDGE)} | ||
onPress={action(selected.id, Action.ACKNOWLEDGE)} | ||
mode={"contained"} | ||
> | ||
Aftekenen | ||
</Button> | ||
<Button | ||
loading={loading.has(Action.ABSENT)} | ||
onPress={action(selected.id, Action.ABSENT)} | ||
mode={"contained-tonal"} | ||
> | ||
Afwezig | ||
</Button> | ||
<Button | ||
loading={loading.has(Action.INSUFFICIENT)} | ||
onPress={action(selected.id, Action.INSUFFICIENT)} | ||
mode={"contained-tonal"} | ||
> | ||
Onvoldoende | ||
</Button> | ||
</View> | ||
</ScrollView> | ||
</Card.Actions> | ||
</Card> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
actions: { | ||
display: "flex", | ||
flexDirection: "row", | ||
gap: 10, | ||
paddingBottom: 10, | ||
}, | ||
}); |
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,18 @@ | ||
import { useAtom, useAtomValue } from "jotai"; | ||
import { getStatus, stateAtom } from "../../stores/corvee"; | ||
import { Button, Card } from "react-native-paper"; | ||
import { ScrollView, StyleSheet, View } from "react-native"; | ||
import { CORVEE } from "../../env"; | ||
import { useContext, useState } from "react"; | ||
import AuthContext, { Authed } from "../../auth"; | ||
import Listing from "./Listing"; | ||
|
||
export default function Selected() { | ||
const state = useAtomValue(stateAtom); | ||
|
||
if (!state) return <></>; | ||
|
||
return state.current.map((selected) => ( | ||
<Listing key={selected.id} selected={selected} /> | ||
)); | ||
} |
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,80 @@ | ||
import { Card, Surface, useTheme } from "react-native-paper"; | ||
import { PaperSelect } from "react-native-paper-select"; | ||
import { StyleSheet, View } from "react-native"; | ||
import Presence from "./presence"; | ||
import { getSlots, Member, Slot, slotsAtom } from "../../stores/register"; | ||
import AuthContext, { Authed } from "../../auth"; | ||
import { AANMELDEN } from "../../env"; | ||
import { useContext } from "react"; | ||
import { useSetAtom } from "jotai"; | ||
|
||
export default function PresenceCard({ | ||
slot, | ||
members, | ||
}: { | ||
slot: Slot; | ||
members: Member[]; | ||
}) { | ||
const theme = useTheme(); | ||
const authState = useContext(AuthContext); | ||
const setSlots = useSetAtom(slotsAtom); | ||
|
||
async function registerManual(user: string) { | ||
if (authState.authenticated !== Authed.AUTHENTICATED) return; | ||
|
||
const token = await authState.token; | ||
await fetch( | ||
`${AANMELDEN}/api/v1/register_manual/${slot.name}/${slot.pod}/${user}`, | ||
{ | ||
headers: { | ||
authorization: `Bearer ${token}`, | ||
}, | ||
}, | ||
); | ||
|
||
setSlots((await getSlots(token)).slots); | ||
} | ||
|
||
if (!slot.presence) return; | ||
|
||
return ( | ||
<> | ||
<PaperSelect | ||
label={"Lid handmatig aanmelden"} | ||
arrayList={members | ||
.sort((a, b) => (a.name < b.name ? -1 : 1)) | ||
.map(({ id, name }) => ({ | ||
_id: id.toString(), | ||
value: name, | ||
}))} | ||
selectedArrayList={[]} | ||
multiEnable={false} | ||
value={""} | ||
onSelection={async (selection) => { | ||
if (!selection.selectedList[0]) return; | ||
await registerManual(selection.selectedList[0]._id); | ||
}} | ||
theme={theme} | ||
textInputStyle={{ | ||
backgroundColor: theme.colors.elevation.level5, | ||
color: theme.colors.onPrimaryContainer, | ||
}} | ||
searchStyle={{ | ||
backgroundColor: theme.colors.elevation.level5, | ||
}} | ||
textColor={theme.colors.onPrimary} | ||
/> | ||
<View style={styles.presence}> | ||
{slot.presence.map((presence) => ( | ||
<Presence key={presence.id} presence={presence} slot={slot} /> | ||
))} | ||
</View> | ||
</> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
presence: { | ||
gap: 5, | ||
}, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const CLIENT_ID = | ||
process.env.EXPO_PUBLIC_CLIENT_ID || | ||
"QI0CNwnSLMJQbsZindMceAhtPR7lQlis0lTcCxGZ"; | ||
export const LEDEN_ADMIN = | ||
process.env.EXPO_PUBLIC_LEDEN_ADMIN || "https://leden.djoamersfoort.nl"; | ||
export const AANMELDEN = | ||
process.env.EXPO_PUBLIC_AANMELDEN || "https://aanmelden.djoamersfoort.nl"; | ||
export const CORVEE = | ||
process.env.EXPO_PUBLIC_CORVEE || "https://corvee.djoamersfoort.nl"; | ||
export const SCOPES: string[] = JSON.parse( | ||
process.env.EXPO_PUBLIC_SCOPES || "null", | ||
) || [ | ||
"openid", | ||
"user/basic", | ||
"user/names", | ||
"user/email", | ||
"media", | ||
"aanmelden", | ||
"corvee", | ||
]; |
Oops, something went wrong.