Skip to content

Commit

Permalink
feat(history): add executor name
Browse files Browse the repository at this point in the history
  • Loading branch information
Ibrahimsyah committed Apr 2, 2024
1 parent 4ef292e commit bb834ff
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/apis/action.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type LastActionResponse = {
export type ActionHistory = {
value: ActionValue
action_by: ActionSource
action_executor: string,
action_at: string,
action: Action
}
5 changes: 2 additions & 3 deletions src/constants/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import WaterDropIcon from '@mui/icons-material/WaterDrop';
import WbIncandescentIcon from '@mui/icons-material/WbIncandescent';

export enum ActionSource {
User = 1,
Scheduler = 2,
Dispatcher = 3,
Scheduler = -1,
Dispatcher = -2,
}

export enum ActionType {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Auth = () => {
})
const auth = useAuthStore()
const navigate = useNavigate()
const notification = useNotification()
const { fire } = useNotification()

const authMutation = useMutation({
mutationFn: (request: AuthRequest) => isLoginState ? userAPI.loginUser(request) : userAPI.registerUser(request),
Expand Down Expand Up @@ -75,9 +75,9 @@ const Auth = () => {
to: '/dashboard',
replace: true,
})
notification.fire(`Selamat Datang ${userInfoQuery.data.name}!`)
fire(`Selamat Datang ${userInfoQuery.data.name}!`)
}
}, [userInfoQuery.data, userInfoQuery.isLoading, navigate, notification])
}, [userInfoQuery.data, userInfoQuery.isLoading, navigate, fire])

return (
<Grid container flexDirection='column' gap={2} sx={{ p: 2, height: '100vh' }} alignItems='center' justifyContent='center' className="fade">
Expand Down
20 changes: 11 additions & 9 deletions src/pages/home/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ const renderModalBody = (item: itemState, mutator: (item: itemState) => void): J
return (
<Grid container justifyContent='space-between' flexDirection='column' gap={2}>
<TextField label="Name" value={item.name} onChange={e => mutator({ ...item, name: e.target.value })} />
<Select value={user.is_active ? "true" : "false"} onChange={(_, val) => mutator({ ...item, is_active: (val as string) == "true" })}>
<Option key="true" value="true">Active</Option>
<Option key="false" value="false">Not Active</Option>
</Select>
<Select value={user.role} onChange={(_, val) => mutator({ ...item, role: Number(val) })}>
<Option key={2} value={2}>User</Option>
<Option key={99} value={99}>Admin</Option>
</Select>
<Grid container justifyContent='space-between' direction='row' gap={2}>
<Select value={user.is_active ? "true" : "false"} onChange={(_, val) => mutator({ ...item, is_active: (val as string) == "true" })}>
<Option key="true" value="true">Active</Option>
<Option key="false" value="false">Not Active</Option>
</Select>
<Select value={user.role} onChange={(_, val) => mutator({ ...item, role: Number(val) })}>
<Option key={2} value={2}>User</Option>
<Option key={99} value={99}>Admin</Option>
</Select>
</Grid>
</Grid>
)
}
Expand All @@ -45,7 +47,7 @@ const renderModalBody = (item: itemState, mutator: (item: itemState) => void): J
return (
<Grid container flexDirection='column' gap={2}>
<TextField label="Name" value={actuator.name} onChange={e => mutator({ ...item, name: e.target.value })} />
<Grid container justifyContent='space-between' direction='row' gap={2}>
<Grid container direction='row' gap={2}>
<TextField sx={{ flex: 1 }} label="Pin Number" value={actuator.pin_number} onChange={e => mutator({ ...item, pin_number: Number(e.target.value) })} />
<TextField sx={{ flex: 1 }} label="Terminal Number" value={actuator.terminal_number} onChange={e => mutator({ ...item, terminal_number: Number(e.target.value) })} />
</Grid>
Expand Down
5 changes: 2 additions & 3 deletions src/pages/home/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ const initialReportState = {
}

const actionSourceNameMap: ({ [key in ActionSource]: string }) = {
[ActionSource.User]: "User",
[ActionSource.Scheduler]: "Otomatis oleh Sistem",
[ActionSource.Dispatcher]: "Oleh Sistem"
[ActionSource.Dispatcher]: "Otomatis oleh Sistem"
}

const Dashboard = () => {
Expand Down Expand Up @@ -213,7 +212,7 @@ const Dashboard = () => {
<Grid container direction='column' alignItems='flex-end'>
<Typography fontSize='xs' textColor={'primary.600'} fontWeight='600'>{dayjs(history.action_at).format("DD-MM-YYYY")}</Typography>
<Typography fontSize='xs' textColor={'primary.600'} fontWeight='600'>{dayjs(history.action_at).format("HH:mm")}</Typography>
<Typography fontSize='xs'>{actionSourceNameMap[history.action_by]}</Typography>
<Typography fontSize='xs'>{history.action_by > 0 ? history.action_executor : actionSourceNameMap[history.action_by]}</Typography>
</Grid>
</Grid>
</Card>
Expand Down
1 change: 0 additions & 1 deletion src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const BottomNavigation = () => {
left: 0,
right: 0,
boxShadow: theme.shadow.sm,
'--joy-shadowChannel': theme.vars.palette[colors[currentIndex]].darkChannel,
[`& .${tabClasses.root}`]: {
py: 1,
flex: 1,
Expand Down
11 changes: 9 additions & 2 deletions src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ const doRequest = async <T>(endpoint: string, config: any): Promise<T> => {
const response = await fetch(buildURL(endpoint), buildRequestConfig(config))
const json = await response.json()
if (!json.is_success || response.status < 200 || response.status > 299) {
if (json.erorr) {
return Promise.reject({
message: json.error,
code: json.code
})
}

return Promise.reject({
message: json.error,
code: json.code
message: "Error",
code: response.status
})
}
return Promise.resolve(json.data)
Expand Down

0 comments on commit bb834ff

Please sign in to comment.