Skip to content

Commit

Permalink
refactor: rewrite Ticket component (#277)
Browse files Browse the repository at this point in the history
Replace storage SDK with REST API.
  • Loading branch information
sdjdd authored May 19, 2021
1 parent 8c1abd4 commit 708fdb2
Show file tree
Hide file tree
Showing 28 changed files with 1,617 additions and 1,285 deletions.
31 changes: 31 additions & 0 deletions api/customerService/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const AV = require('leancloud-storage')
const { Router } = require('express')

const { requireAuth, catchError, customerServiceOnly } = require('../middleware')

const router = Router().use(requireAuth, customerServiceOnly)

router.get(
'/',
catchError(async (req, res) => {
const role = await new AV.Query(AV.Role).equalTo('name', 'customerService').first()
if (!role) {
res.throw(500, 'Missing customer services role')
}
const customerServices = await role.getUsers().query().find({ useMasterKey: true })
res.json(
customerServices.map((user) => {
return {
id: user.id,
nid: user.get('nid'),
email: user.get('email') || '',
username: user.get('username'),
name: user.get('name') || '',
category_ids: user.get('categories')?.map((c) => c.objectId) || [],
}
})
)
})
)

module.exports = router
1 change: 1 addition & 0 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ apiRouter.use('/ticket-fields', require('./TicketField'))
apiRouter.use('/tickets', require('./ticket/api'))
apiRouter.use('/users', require('./user/api'))
apiRouter.use('/categories', require('./category/api'))
apiRouter.use('/customer-services', require('./customerService/api'))
apiRouter.get('/debug/search', parseSearchingQ, (req, res) => {
res.json({ q: req.q, query: req.query })
})
Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import React from 'react'
import { render } from 'react-dom'
import { BrowserRouter } from 'react-router-dom'
import { QueryClient, QueryClientProvider } from 'react-query'

import App from './modules/App'
import './config.webapp'

const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
},
},
})

render(
<BrowserRouter>
<App />
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</BrowserRouter>,
document.getElementById('app')
)
5 changes: 3 additions & 2 deletions modules/About.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react'
import { useTranslation } from 'react-i18next'
import { useTitle } from 'react-use'

import { useTitle } from './utils/hooks'

export default function About() {
const { t } = useTranslation()
useTitle(`${t('about')} - LeanTicket`)
useTitle(t('about'))

return (
<div>
Expand Down
1 change: 1 addition & 0 deletions modules/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class App extends Component {
{!this.state.loading && (
<AppContext.Provider
value={{
currentUser: this.state.currentUser,
isCustomerService: props.isCustomerService,
tagMetadatas: props.tagMetadatas,
addNotification: this.getChildContext().addNotification,
Expand Down
2 changes: 1 addition & 1 deletion modules/CustomerService/Tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ TicketPager.propTypes = {

export default function CustomerServiceTickets() {
const { t } = useTranslation()
useTitle(`${t('customerServiceTickets')} - LeanTicket`)
useTitle(t('customerServiceTickets'))
const { addNotification } = useContext(AppContext)
const [checkedTickets, setCheckedTickets] = useState(new Set())
const customerServices = useCustomerServices()
Expand Down
125 changes: 0 additions & 125 deletions modules/Evaluation.js

This file was deleted.

5 changes: 3 additions & 2 deletions modules/NotFound.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*global SUPPORT_EMAIL*/
import React from 'react'
import { useTranslation } from 'react-i18next'
import { useTitle } from 'react-use'

import { useTitle } from './utils/hooks'

export default function NotFound() {
const { t } = useTranslation()
useTitle('404 - LeanTicket')
useTitle('404')

return (
<div className="jumbotron">
Expand Down
73 changes: 0 additions & 73 deletions modules/Tag.js

This file was deleted.

Loading

0 comments on commit 708fdb2

Please sign in to comment.