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