Commit fd0d4343 authored by Phuengton Chummuel's avatar Phuengton Chummuel

add redux actions

parent 751e5f95
import {
APPOINTMENT_FETCH,
APPOINTMENT_CREATE,
APPOINTMENT_UPDATE,
APPOINTMENT_DELETE
} from './../actions/types'
import realm from './../Database/'
import moment from 'moment'
import { ToastAndroid } from 'react-native'
export const appointmentCreate = ({ id, doctorName, date, place, time }) => {
return (dispatch) => {
let appointment = { id, doctorName, date, place, time }
realm.write(() => {
realm.create('Appointments', {
id: id,
doctorName: doctorName,
date: date,
place: place,
timeStamp: moment().toDate()
})
})
let appointments = realm.objects("Appointments")
dispatch({ type: APPOINTMENT_CREATE, payload: appointments })
}
}
export const appointmentUpdate = () => {
return (dispatch) => {
}
}
export const appointmentFetch = () => {
return (dispatch) => {
let appointments = realm.objects("Appointments")
dispatch({ type: APPOINTMENT_FETCH, payload: appointments })
}
}
export const appointmentDelete = (id) => {
return (dispatch) => {
let item = realm.objects("Appointments").filtered('id == ' + '"' + id + '"')
realm.write(() => {
realm.delete(item)
})
let appointments = realm.objects("Appointments")
dispatch({ type: APPOINTMENT_DELETE, payload: appointments })
}
}
export * from './appointmentActions'
export * from './reminderAction'
\ No newline at end of file
import {
REMINDER_FETCH,
REMINDER_CREATE,
REMINDER_UPDATE,
REMINDER_DELETE
} from './../actions/types'
import realm from './../Database/'
import moment from 'moment'
import { ToastAndroid } from 'react-native'
export const reminderCreate = ({ id, doctorName, date, place, time }) => {
return (dispatch) => {
let appointment = { id, doctorName, date, place, time }
realm.write(() => {
realm.create('Reminder', {
id: id,
doctorName: doctorName,
date: date,
place: place,
timeStamp: moment().toDate()
})
})
let appointments = realm.objects("Reminder")
dispatch({ type: APPOINTMENT_CREATE, payload: appointments })
}
}
export const reminderUpdate = () => {
return (dispatch) => {
}
}
export const reminderFetch = () => {
return (dispatch) => {
let appointments = realm.objects("Reminder")
dispatch({ type: APPOINTMENT_FETCH, payload: appointments })
}
}
export const reminderDelete = (id) => {
return (dispatch) => {
let item = realm.objects("Reminder").filtered('id == ' + '"' + id + '"')
realm.write(() => {
realm.delete(item)
})
let appointments = realm.objects("Reminder")
dispatch({ type: APPOINTMENT_DELETE, payload: appointments })
}
}
export const APPOINTMENT_FETCH = 'APPOINTMENT_FETCH';
export const APPOINTMENT_CREATE = 'APPOINTMENT_CREATE';
export const APPOINTMENT_UPDATE = 'APPOINTMENT_UPDATE';
export const APPOINTMENT_DELETE = 'APPOINTMENT_DELETE';
export const REMINDER_FETCH = 'REMINDER_FETCH';
export const REMINDER_CREATE = 'REMINDER_CREATE';
export const REMINDER_UPDATE = 'REMINDER_UPDATE';
export const REMINDER_DELETE = 'REMINDER_DELETE';
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment