Skip to content

Commit

Permalink
Store email address with incidents
Browse files Browse the repository at this point in the history
  • Loading branch information
majakomel committed Oct 5, 2023
1 parent 295db11 commit 81143d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
8 changes: 8 additions & 0 deletions components/incidents/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as yup from 'yup'
const schema = yup
.object({
title: yup.string().required(),
email_address: yup.string().required(),
reported_by: yup.string().required(),
short_description: yup.string().required(),
ASNs: yup.array().test({
Expand Down Expand Up @@ -145,6 +146,13 @@ const Form = ({ defaultValues, onSubmit }) => {
<Input mb={3} {...field} label="Author*" error={errors?.reported_by?.message} />
)}
/>
<Controller
control={control}
name="email_address"
render={({ field }) => (
<Input mb={3} bg="gray2" {...field} label="Email Address*" error={errors?.title?.message} disabled />
)}
/>
<Flex flexDirection={['column', 'row']} mb={3}>
<Box width={1 / 2} pr={1}>
<Controller
Expand Down
11 changes: 9 additions & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const getBearerToken = () => {
: ''
}

export const getUserEmail = () => {
return typeof localStorage !== 'undefined'
? JSON.parse(localStorage.getItem('bearer'))?.email_address
: ''
}

const axios = Axios.create({ baseURL: process.env.NEXT_PUBLIC_USER_FEEDBACK_API })

export const getAPI = async (endpoint, params = {}, config = {}) => {
Expand Down Expand Up @@ -66,7 +72,7 @@ export const submitFeedback = (feedback) => {

export const loginUser = (token) => {
return axios.get(apiEndpoints.USER_LOGIN, { params: { k: token } }).then(({ data }) => {
localStorage.setItem('bearer', JSON.stringify({ token: data?.bearer, created_at: Date.now() }))
localStorage.setItem('bearer', JSON.stringify({ token: data?.bearer, email_address: data?.email_address, created_at: Date.now() }))
return data
})
}
Expand All @@ -84,8 +90,9 @@ export const deleteIncidentReport = (report) => {
}

export const refreshToken = () => {
const email_address = getUserEmail()
return getAPI(apiEndpoints.TOKEN_REFRESH).then((data) => {
localStorage.setItem('bearer', JSON.stringify({ token: data.bearer, created_at: Date.now() }))
localStorage.setItem('bearer', JSON.stringify({ token: data.bearer, email_address, created_at: Date.now() }))
})
}

Expand Down
2 changes: 2 additions & 0 deletions pages/incidents/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import Form from '/components/incidents/Form'
import useUser from 'hooks/useUser'
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import { getUserEmail } from 'lib/api'

const defaultValues = {
reported_by: '',
title: '',
email_address: getUserEmail(),
text: '',
short_description: '',
published: false,
Expand Down

0 comments on commit 81143d8

Please sign in to comment.