fix date formatting error, introduce date config

This commit is contained in:
kac5a
2023-09-30 13:43:17 +02:00
parent 2f22a57986
commit 728d03fe22
13 changed files with 24 additions and 19 deletions

View File

@@ -160,6 +160,7 @@ RegisterNUICallback('getPlayerData', function(data, cb)
firstname = PlayerData.firstname,
lastname = PlayerData.lastname,
dateofbirth = PlayerData.birthdate,
dateformat = Config.BirthdateFormat,
})
end
end)

View File

@@ -4,6 +4,7 @@ Config.Command = "documents" -- If nil, the command won't work
Config.RegisterKey = nil -- example: "k". If nil, there won't be a key registered. "Config.Command" has to be set to work.
Config.DocumentItemName = nil -- The name of the item you want to open the documents. If nil, no item will be registered. Example: "wallet"
Config.BirthdateFormat = "DD/MM/YYYY" -- The date format your framework uses. By default, ESX: 'DD/MM/YYYY' QB: 'YYYY-MM-DD' Check your identity/multicharacter config!
Config.PaperProp = {
name = "prop_cd_paper_pile1",

View File

@@ -181,7 +181,12 @@ RegisterCallback('k5_documents:getPlayerData', function(source, cb)
'SELECT firstname, lastname, dateofbirth FROM users WHERE identifier = @identifier', {
['@identifier'] = PlayerIdentifier
}, function(result)
cb(result[1])
cb({
firstname = result[1].firstname,
lastname = result[1].lastname,
dateofbirth = result[1].dateofbirth,
dateformat = Config.BirthdateFormat,
})
end)
end)

View File

@@ -1,11 +1,11 @@
{
"files": {
"main.js": "/web/build/static/js/main.a9020f42.js",
"main.js": "/web/build/static/js/main.62d9f438.js",
"static/media/city_logo.png": "/web/build/static/media/city_logo.008b591a2d4e6445d96c.png",
"index.html": "/web/build/index.html",
"main.a9020f42.js.map": "/web/build/static/js/main.a9020f42.js.map"
"main.62d9f438.js.map": "/web/build/static/js/main.62d9f438.js.map"
},
"entrypoints": [
"static/js/main.a9020f42.js"
"static/js/main.62d9f438.js"
]
}

View File

@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/><link href="https://fonts.googleapis.com/css2?family=Oooh+Baby&display=swap" rel="stylesheet"/><title>K5 Documents</title><script type="text/javascript" src="/web/build/config.js"></script><link rel="stylesheet" href="/web/build/customstyle.css"/><script defer="defer" src="/web/build/static/js/main.a9020f42.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="preconnect" href="https://fonts.googleapis.com"/><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/><link href="https://fonts.googleapis.com/css2?family=Oooh+Baby&display=swap" rel="stylesheet"/><title>K5 Documents</title><script type="text/javascript" src="/web/build/config.js"></script><link rel="stylesheet" href="/web/build/customstyle.css"/><script defer="defer" src="/web/build/static/js/main.62d9f438.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,13 +1,11 @@
import styled from "@emotion/styled"
import { Dialog, Box, Grid, Card, CardContent, Typography } from "@mui/material"
import moment from "moment"
import { useContext } from "react"
import { Context } from "../../context/Context"
import city_logo from "../../assets/city_logo.png"
import DocumentTitle from "./Forms/DocumentTitle"
import ViewDocumentField from "./ViewDocumentField"
import SignedArea from "./SignedArea"
import { DATE_FORMAT_SHORT } from "../../utils/consts"
import { texts } from "../../AppConfig"
import { availableJobs } from '../../AppConfig';
@@ -59,7 +57,7 @@ const DocumentView = () => {
</Grid>: <Grid item xs={6}/>}
<Grid item xs={6} >
<IssuerData>{moment(new Date(document?.issuer.birthDate || "")).format(DATE_FORMAT_SHORT)}</IssuerData>
<IssuerData>{document?.issuer.birthDate || ""}</IssuerData>
</Grid>
{document?.issuer.jobName ? <Grid item xs={6}>
<IssuerData>{ document?.issuer.jobName }</IssuerData>

View File

@@ -1,11 +1,9 @@
import styled from "@emotion/styled"
import { Box, Grid, Card, CardContent, Typography, Paper } from "@mui/material"
import moment from "moment"
import city_logo from "../../assets/city_logo.png"
import DocumentTitle from "./Forms/DocumentTitle"
import ViewDocumentField from "./ViewDocumentField"
import SignedArea from "./SignedArea"
import { DATE_FORMAT_SHORT } from "../../utils/consts"
import { useContext } from "react"
import { texts } from "../../AppConfig"
import { DocumentCtx } from "../../providers/DocumentProvider"
@@ -60,7 +58,7 @@ const DocumentViewFromPlayer = () => {
</Grid> : <Grid item xs={6}/>}
<Grid item xs={6} >
<IssuerData>{moment(new Date(document?.issuer.birthDate || "")).format(DATE_FORMAT_SHORT)}</IssuerData>
<IssuerData>{document?.issuer.birthDate || ""}</IssuerData>
</Grid>
{document?.issuer.jobName ? <Grid item xs={6}>
<IssuerData>{ document?.issuer.jobName }</IssuerData>

View File

@@ -37,7 +37,7 @@ const CreateDocument = ({ template, handleCreate, handleClose, logoSrc, isCitize
issuer: {
firstname: playerData?.firstname,
lastname: playerData?.lastname,
birthDate: moment(new Date(playerData?.dateofbirth || "")).format(DATE_FORMAT_SHORT),
birthDate: moment(playerData?.dateofbirth, playerData?.dateformat).format(DATE_FORMAT_SHORT),
jobName: job?.label
}
}
@@ -52,6 +52,7 @@ const CreateDocument = ({ template, handleCreate, handleClose, logoSrc, isCitize
const handleCreateDocument: SubmitHandler<K5Document> = (data: K5Document) => {
let result = {
name: data.name,
createdAt: (new Date()).toString(),
@@ -65,7 +66,7 @@ const CreateDocument = ({ template, handleCreate, handleClose, logoSrc, isCitize
issuer: {
firstname: playerData?.firstname,
lastname: playerData?.lastname,
birthDate: moment(new Date(playerData?.dateofbirth || "")).format(DATE_FORMAT_SHORT),
birthDate: moment(playerData?.dateofbirth, playerData?.dateformat).format(DATE_FORMAT_SHORT),
jobName: !isCitizen ? job?.label : undefined
}
} as K5Document
@@ -120,7 +121,7 @@ const CreateDocument = ({ template, handleCreate, handleClose, logoSrc, isCitize
<Grid item xs={6} />}
<Grid item xs={6} >
<Typography style={{ fontSize: "0.9rem" }}>{moment(new Date(playerData?.dateofbirth || "")).format(DATE_FORMAT_SHORT)}</Typography>
<Typography style={{ fontSize: "0.9rem" }}>{moment(playerData?.dateofbirth, playerData?.dateformat).format(DATE_FORMAT_SHORT)}</Typography>
</Grid>
{!isCitizen ? <Grid item xs={6}>
<Typography style={{ fontSize: "0.9rem" }}>{ job?.label }</Typography>

View File

@@ -57,5 +57,6 @@ type Texts = {
type PlayerData = {
firstname: string,
lastname: string,
dateofbirth: string
dateofbirth: string,
dateformat: string
}