⚡️ improve: Input values for trims (#79)
This commit is contained in:
parent
aa5505f6be
commit
76d22f0572
@ -201,3 +201,23 @@ export function removeTrailingSlash(url) {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function trims(values) {
|
||||||
|
if (typeof values === 'string') {
|
||||||
|
return values.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(values)) {
|
||||||
|
return values.map((value) => trims(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof values === 'object') {
|
||||||
|
let newValues = {};
|
||||||
|
for (let key in values) {
|
||||||
|
newValues[key] = trims(values[key]);
|
||||||
|
}
|
||||||
|
return newValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { useState, useEffect } from 'react';
|
|||||||
import { CHANNEL_OPTIONS } from 'constants/ChannelConstants';
|
import { CHANNEL_OPTIONS } from 'constants/ChannelConstants';
|
||||||
import { useTheme } from '@mui/material/styles';
|
import { useTheme } from '@mui/material/styles';
|
||||||
import { API } from 'utils/api';
|
import { API } from 'utils/api';
|
||||||
import { showError, showSuccess } from 'utils/common';
|
import { showError, showSuccess, trims } from 'utils/common';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
@ -171,6 +171,8 @@ const EditModal = ({ open, channelId, onCancel, onOk, groupOptions }) => {
|
|||||||
|
|
||||||
const submit = async (values, { setErrors, setStatus, setSubmitting }) => {
|
const submit = async (values, { setErrors, setStatus, setSubmitting }) => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
|
console.log(values);
|
||||||
|
values = trims(values);
|
||||||
if (values.base_url && values.base_url.endsWith('/')) {
|
if (values.base_url && values.base_url.endsWith('/')) {
|
||||||
values.base_url = values.base_url.slice(0, values.base_url.length - 1);
|
values.base_url = values.base_url.slice(0, values.base_url.length - 1);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { showError, showSuccess, showInfo } from 'utils/common';
|
import { showError, showSuccess, showInfo, trims } from 'utils/common';
|
||||||
|
|
||||||
import { useTheme } from '@mui/material/styles';
|
import { useTheme } from '@mui/material/styles';
|
||||||
import Table from '@mui/material/Table';
|
import Table from '@mui/material/Table';
|
||||||
@ -256,6 +256,7 @@ export default function ChannelPage() {
|
|||||||
|
|
||||||
const fetchData = async (page, rowsPerPage, keyword, order, orderBy) => {
|
const fetchData = async (page, rowsPerPage, keyword, order, orderBy) => {
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
|
keyword = trims(keyword);
|
||||||
const data = await fetchChannelData(page, rowsPerPage, keyword, order, orderBy);
|
const data = await fetchChannelData(page, rowsPerPage, keyword, order, orderBy);
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
|
@ -101,12 +101,12 @@ export default function TableToolBar({ filterName, handleFilterName, userIsAdmin
|
|||||||
</LocalizationProvider>
|
</LocalizationProvider>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl sx={{ minWidth: '22%' }}>
|
<FormControl sx={{ minWidth: '22%' }}>
|
||||||
<InputLabel htmlFor="channel-type-label">类型</InputLabel>
|
<InputLabel htmlFor="channel-log_type-label">类型</InputLabel>
|
||||||
<Select
|
<Select
|
||||||
id="channel-type-label"
|
id="channel-type-label"
|
||||||
label="类型"
|
label="类型"
|
||||||
value={filterName.type}
|
value={filterName.log_type}
|
||||||
name="type"
|
name="log_type"
|
||||||
onChange={handleFilterName}
|
onChange={handleFilterName}
|
||||||
sx={{
|
sx={{
|
||||||
minWidth: '100%'
|
minWidth: '100%'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { showError } from 'utils/common';
|
import { showError, trims } from 'utils/common';
|
||||||
|
|
||||||
import Table from '@mui/material/Table';
|
import Table from '@mui/material/Table';
|
||||||
import TableBody from '@mui/material/TableBody';
|
import TableBody from '@mui/material/TableBody';
|
||||||
@ -74,6 +74,7 @@ export default function Log() {
|
|||||||
const fetchData = useCallback(
|
const fetchData = useCallback(
|
||||||
async (page, rowsPerPage, keyword, order, orderBy) => {
|
async (page, rowsPerPage, keyword, order, orderBy) => {
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
|
keyword = trims(keyword);
|
||||||
try {
|
try {
|
||||||
if (orderBy) {
|
if (orderBy) {
|
||||||
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect, useCallback } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { showError } from 'utils/common';
|
import { showError, trims } from 'utils/common';
|
||||||
|
|
||||||
import Table from '@mui/material/Table';
|
import Table from '@mui/material/Table';
|
||||||
import TableBody from '@mui/material/TableBody';
|
import TableBody from '@mui/material/TableBody';
|
||||||
@ -71,6 +71,7 @@ export default function Log() {
|
|||||||
const fetchData = useCallback(
|
const fetchData = useCallback(
|
||||||
async (page, rowsPerPage, keyword, order, orderBy) => {
|
async (page, rowsPerPage, keyword, order, orderBy) => {
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
|
keyword = trims(keyword);
|
||||||
try {
|
try {
|
||||||
if (orderBy) {
|
if (orderBy) {
|
||||||
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
||||||
|
@ -22,7 +22,7 @@ import {
|
|||||||
MenuItem
|
MenuItem
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
|
||||||
import { showSuccess, showError } from 'utils/common';
|
import { showSuccess, showError, trims } from 'utils/common';
|
||||||
import { API } from 'utils/api';
|
import { API } from 'utils/api';
|
||||||
import { createFilterOptions } from '@mui/material/Autocomplete';
|
import { createFilterOptions } from '@mui/material/Autocomplete';
|
||||||
import { ValueFormatter, priceType } from './util';
|
import { ValueFormatter, priceType } from './util';
|
||||||
@ -58,6 +58,7 @@ const EditModal = ({ open, pricesItem, onCancel, onOk, ownedby, noPriceModel })
|
|||||||
|
|
||||||
const submit = async (values, { setErrors, setStatus, setSubmitting }) => {
|
const submit = async (values, { setErrors, setStatus, setSubmitting }) => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
|
values.models = trims(values.models);
|
||||||
try {
|
try {
|
||||||
const res = await API.post(`/api/prices/multiple`, {
|
const res = await API.post(`/api/prices/multiple`, {
|
||||||
original_models: inputs.models,
|
original_models: inputs.models,
|
||||||
|
@ -7,7 +7,7 @@ import EditIcon from '@mui/icons-material/Edit';
|
|||||||
import DeleteIcon from '@mui/icons-material/DeleteOutlined';
|
import DeleteIcon from '@mui/icons-material/DeleteOutlined';
|
||||||
import SaveIcon from '@mui/icons-material/Save';
|
import SaveIcon from '@mui/icons-material/Save';
|
||||||
import CancelIcon from '@mui/icons-material/Close';
|
import CancelIcon from '@mui/icons-material/Close';
|
||||||
import { showError, showSuccess } from 'utils/common';
|
import { showError, showSuccess, trims } from 'utils/common';
|
||||||
import { API } from 'utils/api';
|
import { API } from 'utils/api';
|
||||||
import { ValueFormatter, priceType } from './component/util';
|
import { ValueFormatter, priceType } from './component/util';
|
||||||
|
|
||||||
@ -76,6 +76,7 @@ const Single = ({ ownedby, prices, reloadData }) => {
|
|||||||
async (newRow, oldRow, reject, resolve) => {
|
async (newRow, oldRow, reject, resolve) => {
|
||||||
try {
|
try {
|
||||||
let res;
|
let res;
|
||||||
|
newRow = trims(newRow);
|
||||||
if (oldRow.model == '') {
|
if (oldRow.model == '') {
|
||||||
res = await API.post('/api/prices/single', newRow);
|
res = await API.post('/api/prices/single', newRow);
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,7 +6,7 @@ import SubCard from 'ui-component/cards/SubCard';
|
|||||||
import { IconBrandWechat, IconBrandGithub, IconMail, IconBrandTelegram } from '@tabler/icons-react';
|
import { IconBrandWechat, IconBrandGithub, IconMail, IconBrandTelegram } from '@tabler/icons-react';
|
||||||
import Label from 'ui-component/Label';
|
import Label from 'ui-component/Label';
|
||||||
import { API } from 'utils/api';
|
import { API } from 'utils/api';
|
||||||
import { showError, showSuccess, onGitHubOAuthClicked, copy } from 'utils/common';
|
import { showError, showSuccess, onGitHubOAuthClicked, copy, trims } from 'utils/common';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import WechatModal from 'views/Authentication/AuthForms/WechatModal';
|
import WechatModal from 'views/Authentication/AuthForms/WechatModal';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
@ -89,8 +89,11 @@ export default function Profile() {
|
|||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
try {
|
try {
|
||||||
await validationSchema.validate(inputs);
|
let inputValue = inputs;
|
||||||
const res = await API.put(`/api/user/self`, inputs);
|
inputValue.username = trims(inputValue.username);
|
||||||
|
inputValue.display_name = trims(inputValue.display_name);
|
||||||
|
await validationSchema.validate(inputValue);
|
||||||
|
const res = await API.put(`/api/user/self`, inputValue);
|
||||||
const { success, message } = res.data;
|
const { success, message } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
showSuccess('用户信息更新成功!');
|
showSuccess('用户信息更新成功!');
|
||||||
|
@ -17,7 +17,7 @@ import {
|
|||||||
FormHelperText
|
FormHelperText
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
|
||||||
import { renderQuotaWithPrompt, showSuccess, showError, downloadTextAsFile } from 'utils/common';
|
import { renderQuotaWithPrompt, showSuccess, showError, downloadTextAsFile, trims } from 'utils/common';
|
||||||
import { API } from 'utils/api';
|
import { API } from 'utils/api';
|
||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
@ -44,7 +44,7 @@ const EditModal = ({ open, redemptiondId, onCancel, onOk }) => {
|
|||||||
|
|
||||||
const submit = async (values, { setErrors, setStatus, setSubmitting }) => {
|
const submit = async (values, { setErrors, setStatus, setSubmitting }) => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
|
values = trims(values);
|
||||||
let res;
|
let res;
|
||||||
try {
|
try {
|
||||||
if (values.is_edit) {
|
if (values.is_edit) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { showError, showSuccess } from 'utils/common';
|
import { showError, showSuccess, trims } from 'utils/common';
|
||||||
|
|
||||||
import Table from '@mui/material/Table';
|
import Table from '@mui/material/Table';
|
||||||
import TableBody from '@mui/material/TableBody';
|
import TableBody from '@mui/material/TableBody';
|
||||||
@ -60,6 +60,7 @@ export default function Redemption() {
|
|||||||
|
|
||||||
const fetchData = async (page, rowsPerPage, keyword, order, orderBy) => {
|
const fetchData = async (page, rowsPerPage, keyword, order, orderBy) => {
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
|
keyword = trims(keyword);
|
||||||
try {
|
try {
|
||||||
if (orderBy) {
|
if (orderBy) {
|
||||||
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { showError, showSuccess } from 'utils/common';
|
import { showError, showSuccess, trims } from 'utils/common';
|
||||||
|
|
||||||
import Table from '@mui/material/Table';
|
import Table from '@mui/material/Table';
|
||||||
import TableBody from '@mui/material/TableBody';
|
import TableBody from '@mui/material/TableBody';
|
||||||
@ -62,6 +62,7 @@ export default function Token() {
|
|||||||
|
|
||||||
const fetchData = async (page, rowsPerPage, keyword, order, orderBy) => {
|
const fetchData = async (page, rowsPerPage, keyword, order, orderBy) => {
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
|
keyword = trims(keyword);
|
||||||
try {
|
try {
|
||||||
if (orderBy) {
|
if (orderBy) {
|
||||||
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
||||||
|
@ -6,7 +6,7 @@ import UserCard from 'ui-component/cards/UserCard';
|
|||||||
|
|
||||||
import { API } from 'utils/api';
|
import { API } from 'utils/api';
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { showError, showInfo, showSuccess, renderQuota } from 'utils/common';
|
import { showError, showInfo, showSuccess, renderQuota, trims } from 'utils/common';
|
||||||
|
|
||||||
const TopupCard = () => {
|
const TopupCard = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -23,7 +23,7 @@ const TopupCard = () => {
|
|||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
try {
|
try {
|
||||||
const res = await API.post('/api/user/topup', {
|
const res = await API.post('/api/user/topup', {
|
||||||
key: redemptionCode
|
key: trims(redemptionCode)
|
||||||
});
|
});
|
||||||
const { success, message, data } = res.data;
|
const { success, message, data } = res.data;
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
import Visibility from '@mui/icons-material/Visibility';
|
import Visibility from '@mui/icons-material/Visibility';
|
||||||
import VisibilityOff from '@mui/icons-material/VisibilityOff';
|
import VisibilityOff from '@mui/icons-material/VisibilityOff';
|
||||||
|
|
||||||
import { renderQuotaWithPrompt, showSuccess, showError } from 'utils/common';
|
import { renderQuotaWithPrompt, showSuccess, showError, trims } from 'utils/common';
|
||||||
import { API } from 'utils/api';
|
import { API } from 'utils/api';
|
||||||
|
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
@ -66,7 +66,7 @@ const EditModal = ({ open, userId, onCancel, onOk }) => {
|
|||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
|
|
||||||
let res;
|
let res;
|
||||||
|
values = trims(values);
|
||||||
try {
|
try {
|
||||||
if (values.is_edit) {
|
if (values.is_edit) {
|
||||||
res = await API.put(`/api/user/`, { ...values, id: parseInt(userId) });
|
res = await API.put(`/api/user/`, { ...values, id: parseInt(userId) });
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { showError, showSuccess } from 'utils/common';
|
import { showError, showSuccess, trims } from 'utils/common';
|
||||||
|
|
||||||
import Table from '@mui/material/Table';
|
import Table from '@mui/material/Table';
|
||||||
import TableBody from '@mui/material/TableBody';
|
import TableBody from '@mui/material/TableBody';
|
||||||
@ -60,6 +60,7 @@ export default function Users() {
|
|||||||
|
|
||||||
const fetchData = async (page, rowsPerPage, keyword, order, orderBy) => {
|
const fetchData = async (page, rowsPerPage, keyword, order, orderBy) => {
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
|
keyword = trims(keyword);
|
||||||
try {
|
try {
|
||||||
if (orderBy) {
|
if (orderBy) {
|
||||||
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
orderBy = order === 'desc' ? '-' + orderBy : orderBy;
|
||||||
|
Loading…
Reference in New Issue
Block a user